I have a script that operates on 4 folders.

Because they are completely independent, I'm passing in the folder path to a function and then forking that function. It works, but the output to the console is an unreadable disaster.

The main problem is that I cannot tell which folders have been processed and which ones are still going.

One way I have thought of around this problem is to assign a color to the output based on the folder - Red, Green, Blue and Yellow. The idea is that when there is only red output, I know only folder 1 is still being processed.

All my googling about setting colors in bash talks about using echo or passing in the color for specific functions like grep and ls.

Is there a way to set the color at the start of a function?


   set_color $2

#in a loop, process my folders using process_folder $folder $color
  • Sorry, I submitted a close vote, it's a bash script which is on topic. Sorry! – Dave Jan 11 '13 at 9:16

Is there a way to set the color at the start of a function?

It is possible,

echo -e "\e[00;31mRED"

but it could mix colors and make things harder to read. Color your output only.

echo -e "\e[00;31mRED\e[00m"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.