|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi. I am currently redirecting output from a bash script by doing this
in the script: { ....bash commands.. } > "$filename" 2>&1 I now would like to add the option to also display onto the standard output. So I I'd do something like this: { ....bash commands.. } 2>&1 | tee "$filename" The problem I am having, though, is that I'd like to have a script option that will let the user choose one or the other. I tried having a variable like this: redirection_descriptor="> ${filename} 2>&1" or redirection_descriptor="2>&1 | tee ${filename}" based on the user's option. Then I tried to do this: { ....bash commands.. } $redirection_descriptor but that gave me a syntax error on $redirection_descriptor. Any suggestions how to do this? Thanks! Ken |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
2006-12-1, 14:58(-08), kk_oop@yahoo.com:
> Hi. I am currently redirecting output from a bash script by doing this > in the script: > > { > ...bash commands.. > } > "$filename" 2>&1 > > I now would like to add the option to also display onto the standard > output. So I I'd do something like this: > > { > ...bash commands.. > } 2>&1 | tee "$filename" > > The problem I am having, though, is that I'd like to have a script > option that will let the user choose one or the other. I tried having > a variable like this: [...] Easiest is probably to do something like: main () { ...bash commands... } if [ "$opt_t" = true ]; then main 2>&1 | tee -- "$filename" else main > "$filename" 2>&1 fi You could also do: if [ "$opt_t" = true ]; then logging() { tee -- "$filename" } else logging() { cat > "$filename" } fi { ...bash commands... } 2>&1 | logging But that means your bash commands standard output will be a pipe even when that could have been avoided. -- Stéphane |
|
![]() |
| Outils de la discussion | |
|
|