From: kj on 8 Jun 2010 16:35 I have a shell script that executes several commands in sequence, all of which, by default, produce a lot of output, both to stdout and stderr. These commands are heterogeneous, and therefore do not have a common mechanism for specifying verbosity levels; in fact, for some of them, there is no such mechanism at all. Of course, I can silence any one of them with something like some_noisy_command >/dev/null 2>&1 ....but I don't want to hard-code this indirection. Instead I would like to have quiet operation by default, but support verbose operation through a command-line option for the script. I'm really out of my depth here. This naive approach fails (of course): [ -z $VERBOSE ] && DEVNULL='>/dev/null 2>&1' some_noisy_command $DEVNULL What's the right way to implement this verbosity level control? (FWIW I use zsh.) TIA! ~K
From: pk on 8 Jun 2010 16:47 kj wrote: > I have a shell script that executes several commands in sequence, > all of which, by default, produce a lot of output, both to stdout > and stderr. > > These commands are heterogeneous, and therefore do not have a common > mechanism for specifying verbosity levels; in fact, for some of > them, there is no such mechanism at all. > > Of course, I can silence any one of them with something like > > some_noisy_command >/dev/null 2>&1 > > ...but I don't want to hard-code this indirection. Instead I would > like to have quiet operation by default, but support verbose > operation through a command-line option for the script. > > I'm really out of my depth here. This naive approach fails (of > course): > > [ -z $VERBOSE ] && DEVNULL='>/dev/null 2>&1' > some_noisy_command $DEVNULL > > What's the right way to implement this verbosity level control? > > (FWIW I use zsh.) exec 3>&1 4>&2 1>/dev/null 2>/dev/null ....commands here... exec 1>&3 2>&4 3>&- 4>&- ....normal I/O here ...
From: Bill Marcum on 8 Jun 2010 18:43 On 2010-06-08, kj <no.email(a)please.post> wrote: > > > I'm really out of my depth here. This naive approach fails (of > course): > > [ -z $VERBOSE ] && DEVNULL='>/dev/null 2>&1' > some_noisy_command $DEVNULL > > What's the right way to implement this verbosity level control? > eval some_noisy_command $DEVNULL -- [It is] best to confuse only one issue at a time. -- K&R
From: kj on 9 Jun 2010 13:14 In <4286743.ObB369e8A3(a)xkzjympik> pk <pk(a)pk.invalid> writes: >exec 3>&1 4>&2 1>/dev/null 2>/dev/null >...commands here... >exec 1>&3 2>&4 3>&- 4>&- >...normal I/O here ... I see. I always forget this use of exec. (It's a system call with a split personality...) Thanks! ~K
From: kj on 9 Jun 2010 13:15 In <mkt2e7-fbl.ln1(a)marcumbill.bellsouth.net> Bill Marcum <marcumbill(a)bellsouth.net> writes: >On 2010-06-08, kj <no.email(a)please.post> wrote: >> >> >> I'm really out of my depth here. This naive approach fails (of >> course): >> >> [ -z $VERBOSE ] && DEVNULL='>/dev/null 2>&1' >> some_noisy_command $DEVNULL >> >> What's the right way to implement this verbosity level control? >> >eval some_noisy_command $DEVNULL Thanks! ~K
|
Pages: 1 Prev: fgrep,grep and egrep Next: Where is the document for /dev/fd/0? |