383 reputation
28
bio website
location
age
visits member for 2 years, 10 months
seen Apr 18 at 21:38

Apr
17
comment Get bash DEBUG trap to execute only once for and/or lists?
@StephaneChazelas: Thanks for the link. It looks like preexec.bash basically does what I do in my answer (via the preexec_interactive_mode variable), so maybe the approach in my answer is as non-kludgy as it can get. I do wish bash had something like zsh's preexec() hook.
Apr
17
answered Get bash DEBUG trap to execute only once for and/or lists?
Apr
17
asked Get bash DEBUG trap to execute only once for and/or lists?
Apr
14
awarded  Notable Question
Jan
8
comment Shell filename pattern that expands to dot files but not to `..`?
There's a bug in your answer: The "A more complex variant" will pass *, .[!.]*, and/or ..?* to somecommand if those patterns don't match any file. I think you should replace case $x in .|..) continue;; esac with [ -e "$x" ] || continue (like your third bullet point).
Jan
8
comment Using while loop to ssh to multiple servers
The -u option is not supported by POSIX, and thus should not be used for #!/bin/sh scripts; use read HOST <&10 instead. Also, POSIX only requires shells to support file descriptors 0 through 9, so 10<servers.txt can't be used if the script is to be strictly conforming.
Jan
8
comment Using while loop to ssh to multiple servers
Another alternative: exec 3<&0; while read HOST; do ssh $HOST "uname -a" <&3; done <servers.txt; exec 3<&- This makes file descriptor 3 a backup of the original stdin, then uses it for ssh's stdin, then closes the backup FD when done. This works on any POSIX-compatible shell.
Aug
5
revised Why not use “which”? What to use then?
add section headings to make it easier to skim the answer; add a tl;dr section at the top for people who just want to know the answer
Aug
5
suggested suggested edit on Why not use “which”? What to use then?
Jun
29
answered Preventing propagation of SIGINT to Parent Process
Jun
29
comment Preventing propagation of SIGINT to Parent Process
+1 for the clever idea, although beware that the shell's behavior changes when it is an interactive shell (at least the POSIX shell does; I'm not familiar with the details of ksh). Examples: ${ENV} is sourced, the shell won't immediately exit when it encounters an error, SIGQUIT and SIGTERM are ignored.
Jan
23
comment Redirect all subsequent commands' stderr using exec
@StephaneChazelas: You make a good point. I just wanted to point out that the syntax is not supported by the POSIX standard and thus won't universally work in /bin/sh scripts (many people erroneously use bash syntax in /bin/sh scripts).
Jan
21
awarded  Commentator
Jan
21
comment Redirect all subsequent commands' stderr using exec
Note that this uses bashisms -- it may not work in other shells (e.g., dash). But since the question specified bash, +1.
Jan
4
comment $VAR vs ${VAR} and to quote or not to quote
As a general rule, I will always quote variable expansions even when I know the value won't contain any IFS characters because I want to be in the habit. The one exception is I don't quote the value when doing a variable assignment (unless required, such as when the value contains a space). This makes editor syntax highlighting more useful when there are command substitutions such as FOO=$(BAR=$(BAZ=blah; printf %s "${BAZ}"); printf %s "${BAR}"). Rather than coloring everything the "string" color, I get syntax highlighting of the nested code. This is also why I avoid backticks.
Nov
1
awarded  Popular Question
Oct
30
comment Creating a single output stream out of three other streams produced in parallel
Great answer. You may want to do IFS= read -r l || [ -n "${l}" ] in case the last line of output is not terminated with a newline.
Jun
23
awarded  Yearling
May
24
comment Does POSIX guarantee that the standard utilities are in PATH?
Heh, I didn't even notice that getconf PATH in the application usage section. Thanks!
May
24
accepted Does POSIX guarantee that the standard utilities are in PATH?