C code in Bash?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting C code in Bash?
# 1  
Old 10-28-2015
C code in Bash?

Hi everyone, in better attempts to learn Bash shell scripting I've been looking at and reviewing people's bash shell scripts on Github. I'm still reviewing "easier" scripts, trying to follow the logic, syntax etc..

I came across this very odd syntax and it really puzzled me.

echo -e "\033[91mVulnerable to $1\033[39m"
echo -e "\033[93mFound non-exploitable $1\033[39m"

What's all of this \033 and [39m business about?


Upon Googling, I see that it has something to do with C code about line syntax? Does anyone know what this does exactly? Does it have to do with formatting the output?

This brings up a larger question in that can you use C syntax and commands like this in a BASH script? Why would some C code work and others not?
# 2  
Old 10-28-2015
It's nothing to do with C.

The -e, in some very specific versions of the bourne shell, means "enable escape sequences", including octal ones, of the form backslash-zero-digit-digit[-digit]. In most other versions of the Bourne shell, the -e and the backslashes and everything will be dumped literally. printf, though, does support these sequences almost everywhere.

The [91m bit has nothing to do with C or BASH. It just prints a literal [, 9, 1, m. But a terminal supporting ANSI escape sequences will take octal 33, followed by [, 9, 1, m, to mean "change color to bright red".

The 39m means 'switch back to grey', which is a little wrong, as the appropriate thing to do is a reset to default, not what you assume the default to be.

Last edited by Corona688; 10-28-2015 at 02:19 PM..
# 3  
Old 10-28-2015
Look into man console_codes (might be limited to linux). The \033 is the octal representation of the ESC char (used to introduce the codes), and echo's -e option makes it interpret such control chars.
# 4  
Old 10-28-2015
Wow, I've been in and out of linux scripting for like a year now...but I've yet to ever hear of this... Thanks guys! Is this deprecated syntax for bash? Really I don't see the point of it though...
# 5  
Old 10-28-2015
The point is:

linux ls command output in colors
cursor positioning
bolding text
highlighting text - like info command output
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

bash - Validating return code 0

Hi All, I am trying a script out that will startup on one of my servers. i wanted to check for RC 0 and if it didnt check out, exit. Typo- This is BASH (Redhat) This isnt working, and this is the best way to do error checking I feel. Heres my erorr ./start: line 25: syntax error near... (2 Replies)
Discussion started by: jeffs42885
2 Replies

2. Shell Programming and Scripting

Bash FPATH code update

In this post at 302451613-post2.html the link to the code comes up not found. The thread is closed, so I was unable to ask on the thread itself and I do not have enough posts yet to send a private message (or write out a proper html link). Does the author (jim mcanamara) have an updated link? ... (2 Replies)
Discussion started by: matthewpersico
2 Replies

3. Shell Programming and Scripting

Bash code change

I have the below bash which runs great. Before I make a change I wanted to check with experts (as I am not one). After the perl code completes, I am going to display "annotation complete" then go into the remove function . annovar() { # combine id and position files cd... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. Shell Programming and Scripting

Bash code will not run

Why doesn't the code below run? Am I missing something? Thank you :). syntax() { printf "\n\n" printf "Enter HGVS description of variant(s): "; IFS="," read -a hgvs && printf "\n Nothijng entered. Leaving match function." && sleep 2 && return for ((i=0;... (5 Replies)
Discussion started by: cmccabe
5 Replies

5. UNIX for Dummies Questions & Answers

Understanding bash code

I am not able to understand below line in unix bash shell.Could anyone explain what it will do result="${path1}/*${var1}*${var2}*wssreligibleitem*.csv" path1 is defined and it is a directory path var1 is defined and it holds string value like abc var2 is defined and it holds string value like... (6 Replies)
Discussion started by: vamsi.valiveti
6 Replies

6. Shell Programming and Scripting

What's wrong with my bash code?

I want to let sleep 3 in the background and echo $i pkglists="a b c d e f g" f() { local i set -- $pkglists && ((i +=2)) && sleep 3 &;echo $i } f (3 Replies)
Discussion started by: yanglei_fage
3 Replies

7. Shell Programming and Scripting

Help to write bash script code

I am newbie to UNIX. I came across this exercise in one the books.Can anyone help me with this question?????? Write a short Bash script that, given the name of a file as an argument, reads the file name and creates a new file containing only lines which consist of one word. Here is an example... (4 Replies)
Discussion started by: krthknaidu
4 Replies

8. UNIX for Dummies Questions & Answers

Code stripper for bash script..

Dear all, Is there any open source tool for stripping the comments to bash script without affecting the code part? Please give me any reference to it.. Thanks in Advance... (2 Replies)
Discussion started by: Nila
2 Replies

9. Shell Programming and Scripting

xml code in bash shell

Hi, I am trying to develop a bash script that contains an xml code. I want to put the xml code inside the bash script. Is there a way to make that happen?! My goal is to create a script that can allow the user to enter some parameters which can be passed by the script to the xml code :o . ... (2 Replies)
Discussion started by: the wonderer
2 Replies

10. Shell Programming and Scripting

Bash Source Code

Can somebody give me the link to get the source code of BASH? (1 Reply)
Discussion started by: bhargava
1 Replies
Login or Register to Ask a Question