Sitat:
Originally Posted by topcat8
Hei,
Jeg prøver å teste exit status for cleartool lsvtree setningen nedenfor, men det ser ikke ut til å virke på grunn av halen pipe, som det er testing i stedet. Er det en vei rundt dette uten å legge til et tonn nye koden?
[...]
|
bash og ksh93 har pipefail alternativ:
Code:
bash 3.2.25(17)$ ls x|tail
ls: cannot access x: No such file or directory
bash 3.2.25(17)$ echo $?
0
bash 3.2.25(17)$ set -o pipefail
bash 3.2.25(17)$ ls x|tail
ls: cannot access x: No such file or directory
bash 3.2.25(17)$ echo $?
2
bash og zsh har PIPESTATUS / pipestatus array / variabel:
Code:
bash 3.2.25(17)$ ls x|tail
ls: cannot access x: No such file or directory
bash 3.2.25(17)$ echo $PIPESTATUS
2
bash 3.2.25(17)$ ls x|tail
ls: cannot access x: No such file or directory
bash 3.2.25(17)$ echo ${PIPESTATUS[@]}
2 0
Code:
zsh 4.3.4% ls x|tail
ls: cannot access x: No such file or directory
zsh 4.3.4% echo $pipestatus
2 0