Issue
I thought any script launched from a bash environnement that has -e option set would inherit this -e option. It seems it is not the case Below, a bash subshell is launched and -e option is set , echo_set_options is a small script that just echoes its $- value
>( set -e; echo $- ; echo_set_options )
ehimBHs
$-=hB
with echo_set_options just echoing $- :
#!/usr/bin/bash
echo $-
I don't really understand why let -e option be inherited by subshells and not by scripts
Another question : where is it possible to find description of all flags that make $- value ?
I know that e stands for -e option, B means brace expansion , i for interactive, but what about s for instance ? I haven't found the description of $- value
Thanks for your help !
Solution
A subshell is a copy of the existing process created by fork()
ing that process with no execve()
syscall. Consequently, it gets all your state -- all your local variables (not just environment variables) and all your configuration flags.
A script run as a child process is a whole new process, created by a fork()
followed by an execve()
. That execve()
completely replaces the memory image of the process with a new piece of software; environment variables survive, as do open file descriptors, but not any of the process-local memory state.
Answered By - Charles Duffy Answer Checked By - David Goodson (WPSolving Volunteer)