Color STDERR in output

./errorscript.sh 2> >(echo "\e[0;41m$(cat)\e[0m")
This command will take the output of a command and color any STDERR output as a different color (red outline in this case)
Sample Output
This is a normal line
This is an error line # this is red outlined

2
By: tyzbit
2021-08-08 14:28:50

1 Alternatives + Submit Alt

  • This is a bit of a bash hack to catch STDERR and append a log level to it. So for example, if your script has pseudo loglevels like so: echo "INFO - finding files" [ -f ${files} ] || echo "WARN - no files found" Any subcommands that write to STDERR will screw that up Adding 2> >(fb=$(dd bs=1 count=1 2>/dev/null | od -t o1 -A n); [ "$fb" ] && err=$(printf "\\${fb# }"; cat) && echo "ERROR - $err") to the command does the following: 2> Redirect STDERR >( Spawn a subshell (STDERR is then redirected to the file descriptor for this subshell) fb=$(....) get the first byte of input [ "$fb" ] test if there's a first byte && err=$(printf....) save the output to the $err variable && echo "ERROR - $err" append your pseudo loglevel and the error message Heavily borrowed from https://unix.stackexchange.com/questions/33049/check-if-pipe-is-empty-and-run-a-command-on-the-data-if-it-isnt Show Sample Output


    0
    [command] 2> >(fb=$(dd bs=1 count=1 2>/dev/null | od -t o1 -A n); [ "$fb" ] && err=$(printf "\\${fb# }"; cat) && echo "ERROR - $err")
    tyzbit · 2017-10-16 22:22:42 1

What Others Think

Can I share some ideas with you? happy wheels unblocked games
havenhaven · 6 weeks and 2 days ago
This would actually impress so many people, and all the attention would be diverted towards you. Harley Quinn Costume Jacket
sarahjames999 · 6 weeks and 2 days ago
The kind of looks she creates and how she pulls them over is absolutely fantastic and flattering. Freddie Mercury Jacket
sarahjames999 · 6 weeks and 2 days ago
Thanku for providing wonderful information, http://pro-norton.com/">Norton.com/setup | http://www.ukoficecomsetup.uk/">Office.com/setup
paultroy122 · 6 weeks and 1 day ago
If you consider that you do not have lengthy eyelashes or you intend to boost your appearance, there will be nothing far better than resorting to multiple-use eyelashes. Out there, you can find a variety of incorrect eyelashes to pick the one that finest satisfies your needs. Recognizing all the types of incorrect eyelashes, you will certainly make a fast selection. In a very sophisticated make-up, you can not ignore making use of incorrect eyelashes to stand out. Nonetheless, incorrect eyelashes can be used on any occasion, even if it was unneeded to have a lot makeup on the face that day. The idea of false eyelashes is to improve your appearance while the west really feels comfortable as well as positive. https://www.vipcontentonline.com
vipcontentonline · 5 weeks and 6 days ago
I really appreciate this wonderful post that you have provided for us. I feel strongly that love and read more on this topic. I have spent a lot of my spare time reading your content. Thank you a lot. play solitaire
cookieclickeraz · 5 weeks and 6 days ago
Great blog !! You should start many more. I love all the info provided. I will stay tuned. Find out more
bella · 5 weeks and 2 days ago
Never fails to impress us! Thanks for sharing. Ryan | Gutter Cover
Chaddychaddy · 5 weeks and 1 day ago
Go to stickman hook and play the games you likes!
Kenzo99 · 5 weeks and 1 day ago
Oh so sorry but i am not sure about that... Thanks !! jcpenneykiosk
Kenyattaa · 5 weeks ago
Nice and amazing post this one is, thanks for sharing… Target Card Balance Now
Matildaa · 5 weeks ago
You should have used echo with -e flag: ./errorscript.sh 2> >(echo -e "\e[0;41m$(cat)\e[0m")
eliad · 4 weeks and 6 days ago
Thank you for the post. Probably it's used on betsofa.
Chris_1185 · 4 weeks and 2 days ago
Great article with excellent idea!Thank you for such a valuable article. I really appreciate for this great information.. Notícias de Cinema
hammadamir90 · 4 weeks and 1 day ago
Baccarat ( Baccarat ) PTGAME88 We are the service provider. The No. 1 complete baccarat website, bringing the world's leading baccarat game camp that the most popular people come to your mobile phone. You can choose to play baccarat for free visit for further ????????????
Geekstation · 4 weeks and 1 day ago
This is such a great resource that you are providing and you give it away for free. WrestleMania
hammadamir90 · 4 weeks ago
became a searcher,wanting to discover who i was and what made me precise. my view of myself turned into changing. i desired a stable base to start from. i commenced to resist3 stress to behave in ways that i didn’t like any greater,and i used to be delighted by who i in reality become. i got here to feel a good deal extra sure that no one can ever take my region. https://www.hotarticleshop.com
hotarticlee · 4 weeks ago
This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. CMD
hammadamir90 · 3 weeks and 4 days ago
Really very happy to say, Your post is very interesting to read. I never stop myself to say something about it. You’re doing a great job. Keep it up. myaarpmedicare
George487 · 3 weeks and 4 days ago
I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. Ang Mo Kio One
hammadamir90 · 3 weeks and 4 days ago
Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking. Reasons that boyfriend will leave
hammadamir90 · 3 weeks and 4 days ago
We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends. banner
hammadamir90 · 3 weeks and 3 days ago
The yorkshire puppies for sale Diaries
springsside23 · 3 weeks and 2 days ago
Like all puppies, yorkie puppies for sale have to have exercising, a nutritious diet and lots of like and attention from their entrepreneurs. Additionally they have to have standard grooming and further awareness all through housebreaking and obedience education.
springsside23 · 3 weeks and 2 days ago
Hello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website. Please do keep up the great work. Embedded system training
hammadamir90 · 3 weeks and 1 day ago
I have to admit that you have shown a great insperation in this wonderful site. I understood that we should teach a tactical approach in every learning opportunity that we received even in our own ways of learning before teaching technical skills and showing the result to others to come up for successful and contented result and through this i was able to modify each poject that i have specialy this one www.mcdvoice.com thank you
Wehner · 2 weeks and 6 days ago
Well, I learned something. Thank you, I have always wondered what &2>1 and things similar means in bash scripts. Digital Marketing Agency
da32 · 2 weeks and 5 days ago
I really like your writing style, great information, thankyou for posting. fashion
hammadamir90 · 2 weeks and 2 days ago
Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too. Crownpoint back pain doctor
hammadamir90 · 2 weeks and 2 days ago
I have read your blog it is very helpful for me. I want to say thanks to you. I have bookmark your site for future updates. editor for journal articles
hammadamir90 · 2 weeks and 2 days ago
Startups are even more successful in the Bay than anywhere else in California; startups in the Valley are successful 20x more often than the average throughout the state(check on our website https://jatapp.com/). Even more startling, they’re nearly 90x more successful than the lowest areas.
Weent19 · 2 weeks ago
It has never been easy to buy ammo online. Especially the CCI Primers that can be used by an adult. We also offer discrete and overnight shipping to most countries across the globe. CONTACT DETAILS  Website... https://www.rockstoneammo.store Email... rockstoneammo@gmail.com Prvi Partizan Brass 8mm Lebel (8x50mm Rimmed Lebel) Bag of 50Remington Brass 7mm-08 Remington Bag of 50 Weatherby Brass 460 Weatherby Magnum Box of 20 Quality Cartridge Brass 6.5mm-257 Roberts Box of 20 href="https://rockstoneammo.store/product/starline-brass-50-alaskan-2/ " rel="dofollow">Starline Brass 50 AlaskanNosler Brass 260 Remington Bag of 100Sig Sauer Brass 9mm Luger Primed Bag of 100Nosler Custom Brass 8x57mm JS (8mm Mauser) Box of 50Nosler Custom Brass 338 Remington Ultra Magnum Box of 25Nosler Brass 260 Remington Bag of 100Starline Brass 9mm LargoNosler Custom Brass 35 Whelen Box of 50Lapua Brass 260 Remington Box of 100Nosler Custom Brass 264 Winchester Magnum Box of 50 Sierra MatchKing Bullets 284 Caliber, 7mm (284 Diameter) 180 Grain Hollow Point Boat Tail Meister Hard Cast Bullets 45 Caliber (452 Diameter) 230 Grain Lead Round Nose Box of 500 Lehigh Defense Match Solid Flash Tip Bullets 30 Caliber (308 Diameter) 144 Grain Solid Copper Boat Tail Titanium Tip Lead-Free Box of 50 Berger Varmint Bullets 17 Caliber (172 Diameter) 25 Grain Hollow Point Flat Base Box of 200 Berger Varmint Bullets 20 Caliber (204 Diameter) 40 Grain Hollow Point Boat Tail Lehigh Defense Controlled Fracturing Bullets 45 Caliber Subsonic (458 Diameter) 570 Grain Solid Brass Box of 20 Swift A-Frame Bullets 375 Caliber (375 Diameter) 300 Grain Bonded Semi-Spitzer Box of 50Berger Hybrid Target Bullets 284 Caliber, 7mm (284 Diameter) 184 Grain F-Open Hollow Point Boat Tail Lapua Scenar Bullets 338 Caliber (338 Diameter) 300 Grain Hollow Point Boat Tail Box of 100 Lehigh Defense Match Solid Bullets 30 Caliber (308 Diameter) 150 Grain Solid Copper Boat Tail Lead-Free Box of 100 Hornady InterLock Bullets 35 Caliber (358 Diameter) 200 Grain Spire Point Box of 100 Hornady SST Bullets 6.8mm Remington SPC (277 Diameter) 120 Grain InterLock Polymer Tip Spitzer Boat Tail Box of 100 Berger Classic Hunter Hunting Bullets 243 Caliber, 6mm (243 Diameter) 95 Grain Hollow Point Boat Tail Box of 100 Federal Small Pistol Primers #100 Box of 1000 (10 Trays of 100) Federal Premium Gold Medal AR Match Grade Small Rifle Primers #GM205MAR Box of 1000 (10 Trays of 100)Federal Premium Gold Medal Large Pistol Match Primers #150M Box of 1000 (10 Trays of 100) Winchester Small Pistol Primers #1-1/2 Box of 1000 (10 Trays of 100)  CCI Primers #209M Shotshell Magnum Box of 1000 (10 Trays of 100) Remington Large Rifle Magnum Primers #9-1/2M Box of 1000 (10 Trays of 100) Remington Primers #209 Muzzleloading Box of 100 Winchester Large Rifle Magnum Primers #8-1/2M Box of 1000 (10 Trays of 100) Winchester Triple Seven Primers #209 Muzzleloading CCI Primers #209M Shotshell Magnum Box of 1000 (10 Trays of 100) Nosler Brass 6.5 Creedmoor Bag of 100 Federal Large Pistol Magnum Primers #155 Box of 1000 (10 Trays of 100) CCI Primers #209 Muzzleloading Box of 100 Remington Small Pistol Primers #1-1/2 Box of 1000 (10 Trays of 100) CCI Large Rifle Magnum Primers #250 Box of 1000 (10 Trays of 100) CCI Primers #209 Shotshell Box of 1000 (10 Trays of 100)CCI Percussion Caps #10 Box of 1000 (10 Cans of 100) Fiocchi Primers #209 Shotshell Box of 1000 (10 Trays of 100) Federal Large Rifle Primers #210 Box of 1000 (10 Trays of 100) CCI Large Rifle Bench Rest Primers #BR2 Box of 1000 (10 Trays of 100) CCI 50 BMG Primers #35 Box of 500 (5 Trays of 100) Federal Large Rifle Magnum Primers #215 Box of 1000 (10 Trays of 100) CCI Small Rifle 5.56mm NATO-Spec Military Primers #41 Box of 1000 (10 Trays of 100) Federal Premium Gold Medal Large Pistol Magnum Match Primers #155M Box of 1000 (10 Trays of 100)CCI Large Pistol Magnum Primers #350 Box of 1000 (10 Trays of 100) Redding Versa Pak Accessory Kit Redding Match Grade 3BR Powder Measure with Handgun Metering ChamberLapua Brass 223 Remington Box of 100 RCBS MatchMaster Digital Powder Scale & Dispenser Hornady Auto Charge Pro Digital Powder Scale and Dispenser Precision Hardcore Gear Powder Funnel Rack RCBS ChargeMaster 1500 Digital Powder Scale and Dispenser Combo RCBS ChargeMaster 1500 Digital Powder Scale and Dispenser Combo Lee Load-Master Progressive Press Kit 45 ACP CCI Large Rifle Primers #200 Box of 1000 (10 Trays of 100)Federal Premium Gold Medal Large Rifle Match Primers #210M Box of 1000 (10 Trays of 100) Winchester Small Rifle 5.56mm NATO-Spec Military Primers #41 Box of 1000 (10 Trays of 100) Winchester USA Ready Small Pistol Match Primers Box of 1000 (10 Trays of 100) Winchester USA Ready Small Rifle Match Primers Box of 1000 (10 Trays of 100) CCI Small Rifle Primers #400 Box of 1000 (10 Trays of 100) Remington Premier STS Primers #209 Shotshell CCI Small Pistol Magnum Primers #550 Box of 1000 (10 Trays of 100) Federal Premium Gold Medal Small Pistol Match Primers #100M Box of 1000 (10 Trays of 100) Winchester USA Ready Large Pistol Match Primers Box of 1000 (10 Trays of 100) Remington Large Pistol Primers #2-1/2 Box of 1000 (10 Trays of 100) Winchester USA Ready Large Rifle Match Primers Box of 1000 (10 Trays of 100) Remington Small Pistol Primers #5-1/2 Box of 1000 (10 Trays of 100) Hodgdon Titewad Smokeless Gun Powder Vihtavuori N150 Smokeless Gun Powder Hodgdon Trail Boss Smokeless Gun Powder Accurate Nitro 100 Smokeless Gun Powder Hodgdon Retumbo Smokeless Gun Powder Accurate LT-30 Smokeless Gun Powder. Alliant 410 Smokeless Gun Powder Alliant Power Pro 4000-MR Smokeless Gun Powder IMR Enduron 4955 Smokeless Gun Powder Accurate LT-32 Smokeless Gun Powder Alliant e3 Smokeless Gun Powder Hodgdon Triple Seven Black Powder Substitute 50 Caliber Magnum 60 Grain Pellets Package of 50 Goex Olde Eynsford 3F Black Powder 1 lb Goex FFFFg Black Powder 1 lb Federal Premium FireStick Muzzleloading Charge Hodgdon Triple Eight Black Powder Substitute Hodgdon HS6 Smokeless Gun Powder Goex Olde Eynsford 1-1/2F Black Powder 1 lb Hodgdon CFE 223 Smokeless Gun PowderHodgdon Triple Seven Black Powder Substitute 50 Caliber 30 Grain Pellets Pack of 100 Ramshot LRT Smokeless Gun Powder Hodgdon H4895 Smokeless Gun PowderIMR White Hots Black Powder Substitute 50 Caliber #209 Primer Pre-Formed Charges Pack of 72 IMR White Hots Black Powder Substitute 50 Caliber #209 Primer Pre-Formed Charges Pack of 72 Accurate 2520 Smokeless Gun Powder Vihtavuori 24N41 Smokeless Gun Powder Hodgdon Titewad Smokeless Gun Powder Hodgdon Trail Boss Smokeless Gun Powder Ramshot TAC Smokeless Gun Powder IMR 4064 Smokeless Gun Powder IMR 4895 Smokeless Gun Powder Winchester 296 Smokeless Gun Powder IMR 7828 SSC Smokeless Gun Powder Alliant Reloder 25 Smokeless Gun Powder Hodgdon Hornady LEVERevolution Smokeless Gun Powder Accurate Nitro 100 Smokeless Gun Powder Quality Cartridge Brass 400 Whelen Basic Box of 20 Hornady Brass 376 Steyr Box of 50 Quality Cartridge Brass 8x56mm Mannlicher-Schoenauer Box of 20 Quality Cartridge Brass 450 Alaskan Box of 20 Lapua Brass 8x57mm JRS (8mm Rimmed Mauser) Box of 100 Hornady Brass 375 Flanged Magnum Box of 20 Quality Cartridge Brass 30 Gibbs Box of 20 Nosler Custom Brass 9.3x74mm Rimmed Box of 25Weatherby Brass 375 Weatherby Magnum Box of 20 Lapua Brass 7x64mm Brenneke Box of 100 Nosler Custom Brass 9.3x74mm Rimmed Box of 25 Lapua Brass 338 Norma Magnum Box of 100 Starline Brass 500 Auto Max Hornady Brass 338 Marlin Express box of 50 Starline Brass 445 Super Magnum Prvi Partizan Brass 8mm Lebel (8x50mm Rimmed Lebel) Bag of 50 Vihtavuori N568 Smokeless Gun PowderRamshot Enforcer Smokeless Gun Powder Alliant Reloder 33 Smokeless Gun Powder Ramshot Hunter Smokeless Gun Powder href="https://rockstoneammo.store/product/winchester-winclean-244-smokeless-gun-powder/ " rel="dofollow">Winchester WinClean 244 Smokeless Gun PowderAlliant Reloder 50 Smokeless Gun PowderAlliant Reloder 26 Smokeless Gun PowderAccurate 2015 Smokeless Gun PowderRamshot Big Game Smokeless Gun PowderWinchester 572 Smokeless Gun PowderHodgdon Hi-Skor 700-X Smokeless Gun PowderAlliant Reloder 23 Smokeless Gun PowderVihtavuori N165 Smokeless Gun PowderHodgdon H380 Smokeless Gun Powder
lobe123 · 6 days ago
A debt of gratitude is in order for posting this information. I simply need to tell you that I simply look at your site and I discover it exceptionally fascinating and educational. I can hardly wait to peruse bunches of your posts..seo backlinks
Geekstation · 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: