cygwin - Bash subshell for setting SHELLOPTS in a script -
this question not cygwin specific. however, in cygwin mail archive https://cygwin.com/ml/cygwin-announce/2010-08/msg00015.html various instructions setting cygwin specific igncr shellopt variable , 1 of them instruction:
4a. single affected script, add line after she-bang: ~ (set -o igncr) 2>/dev/null && set -o igncr; # comment needed
i understand set -o igncr sets igncr in shellopts. however, not understand why instruction includes invoking in subshell. understand, variables , environment of subshell not stick around in parent process. use of it?
the detail material here in command
(set -o igncr) 2>/dev/null && set -o igncr
is context.
imagine shell script designed run on non-windows machines in cygwin.
normally (not under cygwin) use of set -o igncr
error (as attempting set other invalid set
option.
however, under cygwin set
both meaningful , helpful.
so how write script operates in both places? need test current environment. check specific environment variables, specific paths, etc. or (and similar move away browser-sniffing , feature testing) can check whether current environment supports option attempting set.
so try set throws error if doesn't work try set in sub-shell (and toss error output /dev/null
ignore it) , if (and if) set succeeds (&&
) set in current shell environment well.
Comments
Post a Comment