Whats the meaning of set -e inside the script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Whats the meaning of set -e inside the script
# 1  
Old 12-01-2011
Whats the meaning of set -e inside the script

Hi,

I would like to ask about the meaning or purpose of set -e in the script bash, Does it mean if a wrong command in the script it will close or exit the script without continuation thats what happen if i set it in the terminal.


Thanks in advance
# 2  
Old 12-01-2011
According to the man page for bash:

Code:
set -o <option>
...
  errexit Same as -e.
...

Why not just try it?

Code:
[root@vb1 bin]# set -e
[root@vb1 bin]# ls blah
ls: cannot access blah: No such file or directory
Connection to vb1 closed.

Code:
[root@vb1 bin]# cat myScript
set -e
ls blah
echo Hello

[root@vb1 ~]# ./myScript
ls: cannot access blah: No such file or directory
[root@vb1 ~]#

So, it would appear to mean "when there's an error, exit the current process".
This User Gave Thanks to Scott For This Post:
# 3  
Old 12-01-2011
Quote:
Originally Posted by Scott
According to the man page for bash:

Code:
set -o <option>
...
  errexit Same as -e.
...

Why not just try it?

Code:
[root@vb1 bin]# set -e
[root@vb1 bin]# ls blah
ls: cannot access blah: No such file or directory
Connection to vb1 closed.

Code:
[root@vb1 bin]# cat myScript
set -e
ls blah
echo Hello

[root@vb1 ~]# ./myScript
ls: cannot access blah: No such file or directory
[root@vb1 ~]#

So, it would appear to mean "when there's an error, exit the current process".
Thanks scot

Yup thats what i did in the terminal, thanks also for pointing me out where to find the man page since on my thougth why i can't find the man page for set cause i used man set which it should be in the man page of bash..Thanks

Yup i just want to confirm on the meaning i try it on my terminal and its the same happens as you explain..

Thanks once again.
# 4  
Old 12-01-2011
set is built into bash, but it's also a POSIX feature expected of any shell, which is why there's two man pages.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help needed with shell script to search and replace a set of strings among the set of files

Hi, I am looking for a shell script which serves the below purpose. Please find below the algorithm for the same and any help on this would be highly appreciated. 1)set of strings need to be replaced among set of files(directory may contain different types of files) 2)It should search for... (10 Replies)
Discussion started by: Amulya
10 Replies

2. Shell Programming and Scripting

set -options not working inside for loop?

I'm a beginner in shell scripting (I'm using ksh). I'm manipulating some files and I'm using set -A to transform each read line into a numeric array. However, inside the 'for' loop the options of set (ie '-A') are not recognized (the vi editor doesn't highlight it and it doesn't work). Where... (4 Replies)
Discussion started by: kasumlolla
4 Replies

3. Shell Programming and Scripting

Set terminal width inside a shell script

Hi all, I have a shell script which uses "mailx -H" to get the subject of a email in a Linux system. However, the subject is truncated, and I think it has something to do with the terminal width because it only returns the first 80 characters of each line. I have tried "stty columns"... (7 Replies)
Discussion started by: mezzo
7 Replies

4. UNIX for Dummies Questions & Answers

Whats wrong in the script?

if then if then echo "fst argument is $1 " else if then "fst argument is $1" fi fi fi Can anyone tell me. My requirement is tht pass a string .. Check whether it contains "-". If yes then check if it... (1 Reply)
Discussion started by: nehagupta2008
1 Replies

5. UNIX for Advanced & Expert Users

Whats wrong in this Script ???

PATH="/clocal/mqbrkrs/user/mqsiadm/sanjay" MAIL_RECIPIENTS="xyz@abc.com" Subject="File accessed in last minutes:" find $PATH -type f -amin -1 > temp.txt.$$ cat temp.txt.$$ | \ while read line do fuser -uV $line >> tempmail.txt done cat "$tempmail.txt" | mailx -s "$Subject"... (4 Replies)
Discussion started by: varungupta
4 Replies

6. Shell Programming and Scripting

Whats wrong with this script?

Hi all, #!/bin/ksh BIN=/interface/Gunner age=$1 directory="$2" && directory=. cd "$directory" || exit 1 from=`$BIN/today -$age` cd $BIN for i in `cat filestoarchive.txt`;do cd $i find . -mtime 14 | grep -v '.tar$' | $BIN/dttmfilter | awk '$1<="'$from'"{ print;};' | \ done (2 Replies)
Discussion started by: kayarsenal
2 Replies

7. Shell Programming and Scripting

Whats the meaning of this code

Hi all, I am unable interpret this code ......... nohup $OPSSHLPATH/mkt_sas_load_cic.sh $db_name $process_id $loc_mm > $OPSLSTPATH/mkt_sas_load_cic.out & Thanks ....In advance (7 Replies)
Discussion started by: dhananjaysk
7 Replies

8. UNIX for Dummies Questions & Answers

whats the purpose of the following script?

whats the purpose of the following script? who could run it? To what is the script refering that exceeds 75%? The mailbox? What does sed 's/%//' do? (1 Reply)
Discussion started by: vrn
1 Replies

9. Shell Programming and Scripting

Whats the meaning

What the folowing statements means and whats the use of it ? expr $db_name + 2 >/dev/null 2>&1 Thanks. (7 Replies)
Discussion started by: dhananjaysk
7 Replies
Login or Register to Ask a Question