Bash syntax


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash syntax
# 1  
Old 09-28-2014
Question Bash syntax

Hello,

I have seen this syntax,

Code:
{ ;;};

quite often and I don't know what it means exactly.

It seems like a distinctive thing of Bash, so it's been used for the logo of the last bug,

ShellShock: All you need to know about the Bash Bug vulnerability | Symantec Connect

I have also seen something like,

Code:
VAR='() { ;;}; apt-get install X'

Could anyone explain what does it do or why is it so distinctive of Bash?

Thank you in advance.
# 2  
Old 10-03-2014
I've not come across this before, so on a scrap server, I ran it from the command line. I just got the following output:-
Code:
bash: syntax error near unexpected token `;;'

Your VAR='.... command will simply assign the literal text as shown to the variable VAR

Can you give us a bit more context as to where it was seen. If there is a small and complete bit of code that does something, could you share it? That would give us more to work on.


Kind regards,
Robin
# 3  
Old 10-03-2014
It's not { ;;};, it's { :;};, and it has been shown/used to demonstrate the shell shock vulnerability. The entire variable assignment above contains an (empty; or better: do nothing) function definition, followed by a command THAT IS NOT MEANT TO RUN but is executed by bash due to its vulnerability.
These 2 Users Gave Thanks to RudiC For This Post:
# 4  
Old 10-03-2014
Hi,

Over the years I have seen this syntax several times, in a case like this it is down to the user to chose the appropriate text.

As an example, a piece of testing code we use. The code is used to attempt to grab all the process table resource on a virtual system.

Code:
fork_proc() { fork_proc XX fork_proc & } ; fork_proc

The code,

Code:
fork_proc()

Is the routine definition, followed by what the code actually does in the braces. In this case, run a process - pass the output to the process and put it in the background.

Code:
{ fork_proc XX fork_proc & }

Followed by the commad it's self.

Code:
; fork_proc

Could just as easilly be written as,

Code:
:(){ : XX :& };:

We use the above as a test to ensure that solaris zones are correctly configures, this is one of several routines used to ensure that the zone has a correctly configured process table and that it won't impact the performance of a global zone.


Regards

Dave
This User Gave Thanks to gull04 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Syntax error in subtraction in Bash

I am sharing a code snippet. for (( i=0; i<=$(( $count -1 )); i++ )) do first=${barr2} search=${barr1} echo $first echo "loop begins" for (( j=0; j<=5000; j++ )) do if } == $search ]]; then echo $j break; fi done second=${harr2} echo $second (2 Replies)
Discussion started by: ngabrani
2 Replies

2. Shell Programming and Scripting

Bash syntax problem

Hello! i try to understand the art of bash scripting but unfortunately, more i try and less i understand it. Can someone tell me how i can learn its logic? i will give you an example why its making me crazy. Look at this basic script: my for loops are working like this, but it took me more than... (10 Replies)
Discussion started by: sablista
10 Replies

3. Shell Programming and Scripting

Bash calling a few functions syntax error

In the bash function below if the user selets "y" then the menu function is called and if they select "n" the move function is called. That all seems to work, my question is after the files are moved an echo, line in bold is displayed and another function called backup is called. I am getting a... (1 Reply)
Discussion started by: cmccabe
1 Replies

4. Shell Programming and Scripting

Bash function using variable in it syntax error

The below bash function uses multiple variables CODING, SAMPLE, SURVEY, andvariant in it. The user selects the cap function and details are displayed on the screen using the $SURVEY variable, the directory is changed to $SAMPLE and the samples.txt is opened so the user can select the sample to... (6 Replies)
Discussion started by: cmccabe
6 Replies

5. Shell Programming and Scripting

-bash: syntax error near unexpected token `('

// AIX 6.1 I am getting a syntax error below. Please advise what to be corrected. :confused: runmqsc CERN.$(echo `hostname` | cut -d'.' -f1 | tr '' '').$(echo $environment | tr '' '') <<! | egrep -i '(FROM.NC.APPLIANCE)' | sort -u |awk '{print $2}' | cut -d '(' -f2 | cut -d ')' -f1 |... (1 Reply)
Discussion started by: Daniel Gate
1 Replies

6. Shell Programming and Scripting

Bash syntax error

while read line do mkdir $line scp -r Docking_results/docking_$line.pdb $line/ cd /$line/ set a=`grep ENDMDL docking_'$line'.pdb | wc -l` set b=`expr $a - 2` csplit -k -s -n 3 -f docking_'$line'. docking'$line'.pdb '/^ENDMDL/+1' '{'$b'}' foreach f (... (4 Replies)
Discussion started by: chrisjorg
4 Replies

7. Web Development

Bash Script, ec2addtag syntax?

ec2addtag --region us-west-1 vol1234 --tag Name=$nameinst; It should execute ec2addtag --region us-west-1 vol1234 --tag Name=webserver; Instead it thinks that Name is equal to that variable. Please help. Thanks! Please use code tags! (0 Replies)
Discussion started by: svalenciatech
0 Replies

8. Shell Programming and Scripting

Bash syntax behaviour : [[ vs [

Hello. In the following : RESTORE_FF contain a file name : a_file.tar.gz I am testing in a directory if "a_file.tar.gz" exists and or if any file like "a_file.tar.gz" exists. So "a_file.tar.gz" will give me file exists So "a_file.tar.gz." will give me file exists So... (5 Replies)
Discussion started by: jcdole
5 Replies

9. Shell Programming and Scripting

Solaris bash syntax different from Linux?

I have a script that's meant to check the disk usage on a particular volume and delete the oldest logfile if it's over a certain percentage. It runs fine on a Linux machine, but on a Solaris one, I get this error: diskspace_check.sh: syntax error at line 3: `diskspace=$' unexpected I assume... (2 Replies)
Discussion started by: cara_k
2 Replies

10. Shell Programming and Scripting

BASH Script syntax error

I'm trying to write a simple script that takes all the .tar.gz files in a directory and verifies them by using the gzip -tv command: for zip in *.tar.gz do gzip -tv $zip if ; then #Check return code from tar echo "File ${zip} verified OK." exit... (4 Replies)
Discussion started by: kelldan
4 Replies
Login or Register to Ask a Question