Can anyone explain this line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Can anyone explain this line
# 1  
Old 12-06-2013
Can anyone explain this line

Hello,
Can anyone explain this line of code
Code:
echo -e "\033[0;32m${1}\033[m"


What does '\033' do
what does [0;32m do
what does [m do?

I tried testing this line using a script
Whatever i pass as input to the script it is spit out

the developer could have simply said echo $1
why did he use all of this " \033[0;32m${1}\033[m "

Thanks,
R
# 2  
Old 12-06-2013
# 3  
Old 12-06-2013
# 4  
Old 12-06-2013
-e turns on to interpret escape sequences (-E disables)
\033 is the hexadecimal representation of ASCII 027, which is the escape code

Thinking back to early programming days, we would often send an escape character followed by other characters to turn on a function. For instance to make something bold, change color, change spacing.
Thus, my thinking is that the first code
[0;32m is to turn on something, while
\033[m is the escape character and a code to turn it back off.

I do not recognize either segment. Then again, it has been a long time since I had to send escape sequences to output (screen, printer) devices.
# 5  
Old 12-06-2013
As noted above, these are ANSI terminal escape codes recognized by several terminals and terminal emulators. In this case, \033[0;32m, requests that following text be printed in green, and \033[0m returns to normal text display. So whatever $1 expands to will be displayed in green.
This User Gave Thanks to Don Cragun For This Post:
# 6  
Old 12-06-2013
Thank you joeyg and Don Cragun for the wonderful explanation; However what could be the reasons when you dont require coloring, can you explain a scenario where coloring helps..
To me without understanding the concept behind coloring ; it simply looks to me as adding unnecessary complexity to the code.
# 7  
Old 12-06-2013
We explained what one echo statement does for you. There is no way for us to guess why the person who wrote that code decided that that text should be printed in green. You'll have to either ask the person who wrote the code why (s)he did that or ask the people who run that script if they want that text to be presented that way.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How I can explain this?

Hi friends! I'm learning UNIX and I have a small question. Working with Shell, i put the name of one executable (in c language) + one number and it says this: $ gcc misterioso_4.c $ ./misterioso_4 6 got: , I can not find an answer in the manual because I havent applied any variable.... (5 Replies)
Discussion started by: dakota
5 Replies

2. Shell Programming and Scripting

anyone can explain this?

why the case 2 will happen ? , ' should stop the history substitution ,shouldn't it? case 1 # echo "123"|sed '/123/!d' 123 case 2 # echo "123 > 456 > 1 > "|sed '/123/!d' -bash: !d': event not found case 3 # echo "123 > 456 > 12 > "|sed '/123/'\!d 123 # bash --version (1 Reply)
Discussion started by: justlooks
1 Replies

3. Shell Programming and Scripting

Explain $# please

I'm trying to follow a script and I see it begins with this: if ; then if ; then print "blah $0 blah blah " exit fi fi What does $# mean? I found out that $1 refers to the shell environment and the last argument that was entered or passed in the previous command. I couldn't find $#... (2 Replies)
Discussion started by: MaindotC
2 Replies

4. Homework & Coursework Questions

Could anyone help explain this?

1. The problem statement, all variables and given/known data: I have a retake assignment to complete for my computer networks and OS class. This isn't really my area, had I known last year I could have swapped it for a different module I would have done so. I'm determined to get through it... (6 Replies)
Discussion started by: Squall Moogle
6 Replies

5. AIX

can anyone explain this?

this is the mksys b script.... can anyone explain .. what # and 1 in if condition this is the first line of the script... it is not from middle of the script.... if then echo "Not enough parameters, need a client name for mksysb" Usage="Usage: $0 <client name>" ... (2 Replies)
Discussion started by: honeym210
2 Replies

6. Shell Programming and Scripting

please explain the below

could u please convert the below statement to shell script ---------- logdir=/smp/dyn/logfiles/cpm/pgm/pgIm $logdir = $logdir ."/pgIm${toDate}*"; ---- could u please explain the below clearly grep -i adding $logdir | grep -iv equation | awk '{print \$NF}' | sort -u | sed -e... (1 Reply)
Discussion started by: mail2sant
1 Replies

7. Shell Programming and Scripting

Please can any one explain this ${0##/}

I did not understand what is ${0##/} PGM=${0##/} TMP=/tmp/${PGM}.$$ Please explain me. (2 Replies)
Discussion started by: gadege
2 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. Shell Programming and Scripting

can anyone explain this?

:start /@~/{ h s/\(.*\)@~.*$/\1/ s/@~$// s/@~/\ /g p g s/.*@~\(.*\)/\1/ } //{ N s/\n/ / b start } (2 Replies)
Discussion started by: djkane
2 Replies

10. UNIX for Dummies Questions & Answers

Please explain this command line ?

Please explain this command line ? wc<infile<newfile Thanx, Saneesh Joseph. (2 Replies)
Discussion started by: saneeshjose
2 Replies
Login or Register to Ask a Question