Errexit APPEARS set in subshells


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Errexit APPEARS set in subshells
# 1  
Old 05-31-2016
Errexit APPEARS set in subshells

Hi there,

Everyone knows that errexit is NOT inherited by subshells. But does anyone know why errexit still appears as set with set +o?

The following example highlights the fact that errexit appears set in a subshell (set +o) even though it's actually unset (it does NOT exit with false).

Code:
$ cat /tmp/test
#!/bin/bash

set -o errexit

_f() {
        set +o | grep errexit
        false
        echo "I'm still here!"
}

_f "$@" && true
_f "$@"
$
$ bash /tmp/test
set -o errexit       <-- errexit appears set         (unexpected)
I'm still here!      <-- but it's actually unset      (expected)
set -o errexit       <-- errexit appears set          (expected)
                     <-- indeed it exited with false  (expected)

Thanks for sharing ideas.

Regards
Santiago
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Export variables to subshells

So i have a script that is like this: #!/bin/sh VARA="elementary 1 elementary 2 nursery A nursery B highschool AZ" echo "${ContentOfADifferentSCRIPT}" | sh i do not have control over the script that is inside the variable "${ContentOfADifferentSCRIPT}". however, i know that the... (3 Replies)
Discussion started by: SkySmart
3 Replies

2. UNIX for Dummies Questions & Answers

Understanding the concept behind subshells

Can someone post a "for dummies" explanation on how subshells work? Let's say I want to get a couple of pieces of info from the /etc/passwd file and set them as variables to be echo'd back after all data is gathered. something like for i in ${grep 5000 /etc/passwd | cut -d : -f 5}... (5 Replies)
Discussion started by: flyboynm
5 Replies

3. UNIX for Dummies Questions & Answers

Identifying the commands creating subshells

Hi all, This is the basic question. I have read many books which advised to avoid creating sub shells. e.g: use wc -l<filename rather than using cat file|wc -l. So, how to identify whether a command creates subshell or not? so,is it better to use tail -n+1 file in stead of using cat.... (3 Replies)
Discussion started by: pandeesh
3 Replies

4. AIX

oracle process appears to die

periodically my oracle 11.2.0.1 listener process 'tnslsnr' seems to crash and disappear ( I am using an AIX 6.1 unix platform ). When this happens I am able to restart my listener ok. However when this happens there is is no stop recorded in my listener log (as there normally would be - hence why I... (1 Reply)
Discussion started by: jimthompson
1 Replies

5. UNIX for Dummies Questions & Answers

print records where an ID appears more than once

Hi everyone! I have something like the following records in a file: ID: 1 Name: A Age: 23 ID: 2 Name: B ID: 1 Activity: Climbing ID: 3 Name: C ID: 3 Activity: Skating I want to capture the records where the field Age exists AND the records that have the same ID as the one... (4 Replies)
Discussion started by: Atrisa
4 Replies

6. Shell Programming and Scripting

Question regarding shells and subshells when a script is run

I have the following script running with nohup on one of my servers: #!/bin/bash #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ #set log number #i=1 #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ #Check if log exits, if so incrememnt log number up so we don't clobber #while... (8 Replies)
Discussion started by: DeCoTwc
8 Replies

7. Shell Programming and Scripting

delimiter appears in field

The typical line of the input file is as follows, 123|abcde|"xyz|mn"|ghelosa|3455hello| The delimiter is |. I need to change it to another delimiter, say ~. For the above line, the output should be: 123~abcde~xyz|mn~ghelosa~3455hello~ The challenge is when | appears in a field, it... (2 Replies)
Discussion started by: derekxu
2 Replies

8. UNIX for Dummies Questions & Answers

appears 4 or more time

I have a file like this: 111 AA 100.00 111 AA 200.00 TOTALS 2 300.00 111 285.00 111 ... (0 Replies)
Discussion started by: nickg
0 Replies

9. Shell Programming and Scripting

Killing parent shells from subshells (KSH)

Hi all, I have a shell script which calls other shell scripts, depending on the input. Within a.sh, I have a command which calls b.sh (ie. ksh b.sh) Normally, we use the exit function to terminate a shell. However, if I choose to call exit from b.sh, I will return to the parent shell who... (4 Replies)
Discussion started by: rockysfr
4 Replies
Login or Register to Ask a Question