How to inherent non-zero exit status using pipe?

2010-08-11 Thread Peng Yu
Hi, The following example returns the exit status of the last command in a pipe. I'm wondering if there is a way to inherent non-zero exit status using pipe. That is, if there is any command in a pipe that return a non-zero status, I'd like the whole pipe return a non-zero status. $ cat main.sh

Re: How to inherent non-zero exit status using pipe?

2010-08-11 Thread Pierre Gaston
On Wed, Aug 11, 2010 at 2:18 PM, Peng Yu pengyu...@gmail.com wrote: Hi, The following example returns the exit status of the last command in a pipe. I'm wondering if there is a way to inherent non-zero exit status using pipe. That is, if there is any command in a pipe that return a non-zero

Re: How to inherent non-zero exit status using pipe?

2010-08-11 Thread Eric Blake
On 08/11/2010 05:20 AM, Pierre Gaston wrote: On Wed, Aug 11, 2010 at 2:18 PM, Peng Yu pengyu...@gmail.com wrote: Hi, The following example returns the exit status of the last command in a pipe. I'm wondering if there is a way to inherent non-zero exit status using pipe. That is, if there is

Re: How to inherent non-zero exit status using pipe?

2010-08-11 Thread Eric Blake
On 08/11/2010 07:46 AM, Eric Blake wrote: On 08/11/2010 05:20 AM, Pierre Gaston wrote: On Wed, Aug 11, 2010 at 2:18 PM, Peng Yu pengyu...@gmail.com wrote: Hi, The following example returns the exit status of the last command in a pipe. I'm wondering if there is a way to inherent non-zero

Re: How to inherent non-zero exit status using pipe?

2010-08-11 Thread Dennis Williamson
However, if your pipe is in a command substitution or other subshell, PIPESTATUS won't be useful. You'll have to use pipefail. $ set +o pipefail $ var=$(false | true) $ declare -p PIPESTATUS# shows the status of the assignment, not the false declare -a PIPESTATUS='([0]=0)' $ var=$(false |

return from function doesn't work when used in tail of pipeline

2010-08-11 Thread Martin Schwenke
Configuration Information [Automatically generated, do not change]: Machine: i486 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale'

read -d'' -n1

2010-08-11 Thread Jan Schampera
Hello, don't ask about the detail how I originally invented this code, but I stepped over something I really can't explain: 1) Why doesn't this print anything while read -d'' -n1 ch; do echo $ch done $'hello\nworld' 2) Why does this print something, but only up to the hyphen? while

Re: read -d'' -n1

2010-08-11 Thread Jan Schampera
Jan Schampera wrote: 1) Why doesn't this print anything while read -d'' -n1 ch; do echo $ch done $'hello\nworld' 2) Why does this print something, but only up to the hyphen? while read -d'' -n1 ch; do echo $ch done $'hello\nwor-ld' Please ignore this question. 2 minutes after

Re: read -d'' -n1

2010-08-11 Thread Sharuzzaman Ahmat Raslan
Hi Jan, Which part is the mistake, and what is the solution? Thanks On Thu, Aug 12, 2010 at 1:46 PM, Jan Schampera jan.schamp...@web.de wrote: Jan Schampera wrote: 1) Why doesn't this print anything while read -d'' -n1 ch; do echo $ch done $'hello\nworld' 2) Why does this print