Usage of flower braces {} with test command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Usage of flower braces {} with test command
# 1  
Old 08-20-2015
Usage of flower braces {} with test command

hello team,

I'm facing the problem with below code set with usage of {},
i want to use {} instead of (), as i don want bash to fork a new shell.

Source :
If you invoke the exit in a subshell, it will not pass variables to the parent. Use { and } instead of ( and ) if you do not want Bash to fork a subshell.

Code:
[ "`locate *asdfghjcluster_info*`" == "" ] && {echo  - ERROR : required cluster_info NIPE file used for installation/upgrade is missing.. exiting..; exit 1; }

But the ouput is :
Code:
./try_pet_ha_service_restart_automation.sh: line 26: syntax error near unexpected token `}'
./try_pet_ha_service_restart_automation.sh: line 26: `[ "`locate *asdfghjcluster_info*`" == "" ] && {echo  - ERROR : required cluster_info NIPE file used for installation/upgrade is missing.. exiting..; exit 1; }'

i want the "exit" inside {}, should exit the script execution.

Regards,
Chandana
# 2  
Old 08-20-2015
put the first command on a new line, and last brace to i think
This User Gave Thanks to gwillie For This Post:
# 3  
Old 08-20-2015
There is a space missing after the opening curly brace and I'd put the output into quotes:
Code:
[ "`locate *asdfghjcluster_info*`" == "" ] && { echo  "- ERROR : required cluster_info NIPE file used for installation/upgrade is missing.. exiting.."; exit 1; }

This User Gave Thanks to cero For This Post:
# 4  
Old 08-20-2015
You haven't said what OS and shell you're using, so you should also be aware that the way echo behaves when its 1st argument starts with a minus sign (as in your code) or has any argument that contains a backslash character, varies from operating system to operating system and from shell to shell. For portable code, printf would be better than echo as in:
Code:
[ "`locate *asdfghjcluster_info*`" == "" ] && { printf '%s\n' "- ERROR : required cluster_info NIPE file used for installation/upgrade is missing.. exiting.."; exit 1; }

This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 08-20-2015
It wants a space (or a newline) between { and echo.
Further a leading - can mean an option to the echo command, and the shell evaluates the text and might stumble on a ..
The following fixes it:
Code:
{ echo  " - ERROR : required cluster_info NIPE file used for installation/upgrade is missing.. exiting.."; exit 1; }

This User Gave Thanks to MadeInGermany For This Post:
# 6  
Old 08-25-2015
Thanks,

Both the commands worked..!Smilie

{ echo "- ERROR : required cluster_info NIPE file used for installation/upgrade is missing.. exiting.."; exit 1; }

{ printf '%s\n' "- ERROR : required cluster_info NIPE file used for installation/upgrade is missing.. exiting.."; exit 1; }

Regards,
Chandana
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Usage of '.' in MV command

Hi, Could you please let me know, why we should not use '.' in move command, if we use it, is it something wrong.. Please share the details on it. /home/rahualux/emp.csv /home/rahualux/details/employee_files/. Or other example for mutlipile files /home/rahualux/*.csv... (3 Replies)
Discussion started by: rahualux
3 Replies

2. Shell Programming and Scripting

For getting value between the braces

Hi I have a file called tmp with the content as belowmore tmp NAMELIST(Hari) NAMELIST(Raju) I want to get the values between the brackets. When I executed the below command on zlinux I get the output which I wantedmore tmp |awk -F'' '{print $2}' But when I execute the same in... (3 Replies)
Discussion started by: harimhkr
3 Replies

3. Shell Programming and Scripting

cp -v command usage?

I am trying to output a log file from cp usage. I think this can be achieved. In my code I have this. cp -i -v ~/files/* ~/backups/oldfiles/;; > ~/logs/logfile.logThe error I get is "syntax error near unexpected token '>' What am I missing? (7 Replies)
Discussion started by: gameinn
7 Replies

4. UNIX for Dummies Questions & Answers

Command to display the space usage (memory usage) of a specific directory.

Hi all, Can you please tell me the command, with which one can know the amount of space a specific directory has used. df -k . ---> Displays, the amount of space allocated, and used for a directory. du -k <dir name> - gives me the memory used of all the files inside <dir> But i... (2 Replies)
Discussion started by: abhisheksunkari
2 Replies

5. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

6. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

7. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

8. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

9. Shell Programming and Scripting

How do l test for carriage return & Disk space usage

Hi, I have just written a script in /bin/bash, however, l want to test if character is a carriage return or space. Also l want my script to be able to detect my disk space and send a mail if usage is more than 90% or send an alert. Thanks Kayode (6 Replies)
Discussion started by: kayode
6 Replies
Login or Register to Ask a Question