Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

curly bracket

Status
Not open for further replies.

afender99

MIS
Dec 5, 2003
7
SG
Hi

{ fbackup $backup_type -u $verbose_option $hidden_option $nfs_option -g
$graph_file $index_option -c $config_file -d $fbackupfiles -f - | tcio -ove $rew
ind -S 8 $device
} 2>&1

this is what i extracted from the br_backup script, very curious of the use of curly bracket, any significant use there?

rgs

afender99
 
The brackets are used for grouping, similar to the use of open/close parenthesis. The curly braces will execute the commands between the opening/closing brace in the current shell, whereas if you used parenthesis, the commands would be executed in a sub-shell.
 
hi uvguy

thks for ur reply ..what if i never put parenthesis and curly bracket..would it matters?

rgs

afender99
 
then i think the '2>&1' at the end would apply only to the last command in the pipeline and not to all the commands in the pipeline.

so if you redirect the output of this line to some file say 'log' (with '> log'), you would find in that file only errors from the last 'tcio' command. the errors from the other commands (fbackup) would simply be displayed on the terminal (assuming you did not redirect errors using '2>file').
 
Then output upto fbackupfiles -f - will go to command tcio but standard error will go to standard output i.e your display.

Patel
 
standard error wont go to standard output unless it is redirected. and standard error, by default, is the display. standard error is also the display, by default.

so in the absence of curly brackets: the output from the fbackup command should go to the tcio command. the errors from fbackup command should go to the display. the errors from the tcio command should go to the standard output.

of course if the standard output is not redirected, all of this will appear on the display. it will look as if the curly brackets did not achieve anything.

you can see the difference when you put that line in a shell script (say 'mybackup') and execute it with stdout redirect with '>' to a file (as 'mybackup > mybkp.log'). try it with and without the curly brackets. make sure you give fbackup enough to complain about, else you wont have any errors!

here is a simple example:
--------------------------------------------
bash-2.01$ cat bkt.sh
#! /bin/sh
touch file1
rm -f file2
ls -l file1 file2 | grep file1 2>&1
echo ----
{ ls -l file1 file2 | grep file1
} 2>&1

bash-2.01$ sh bkt.sh > log
file2 not found

bash-2.01$ cat log
-rw-rw-r-- 1 rangarc lang 0 Jan 29 13:11 file1
----
file2 not found
-rw-rw-r-- 1 rangarc lang 0 Jan 29 13:11 file1

bash-2.01$ sh bkt.sh
file2 not found
-rw-rw-r-- 1 rangarc lang 0 Jan 29 13:11 file1
----
file2 not found
-rw-rw-r-- 1 rangarc lang 0 Jan 29 13:11 file1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top