Re: Bash help requested: Capturing command errors within pipes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Steven W. Orr wrote:
On Thursday, Mar 19th 2009 at 14:11 -0000, quoth Daniel B. Thurman:

=>S P Arif Sahari Wibowo wrote:
=>> On Thu, 19 Mar 2009, Daniel B. Thurman wrote:
=>> > How could one go about capturing command errors within pipes?
=>> =>> The variable $PIPESTATUS is just for that. =>> =>I tried it, seems not to work.
=>
=>Try capturing a sed error when re1 or re2 has a bad regular
=>expression string.  I have not been able to catch the error.

Sorry, but you'll have to supply something more specific. It's possible for a program to have an error but not return a proper exit status.

But so far, my highly scientific test has revealed that all is good in pipe testing land in the Kingdom of Bash.

578 > true | false | true | true
579 > echo ${PIPESTATUS[@]}
0 1 0 0

OK, I found out why I had a problem!

I setup an intentional sed error:
$ (re="-e '\'s/b/h/'"; echo "boo" | sed $re | echo "done"; echo ${PIPESTATUS})
done
sed: -e expression #1, char 1: unknown command: `''
0

Same thing but with @ pipe status expression
$ (re="-e '\'s/b/h/'"; echo "boo" | sed $re | echo "done"; echo ${PIPESTATUS[@]})
done
sed: -e expression #1, char 1: unknown command: `''
0 1 0

My problem was that the last command was OK, of which
PIPESTATUS was reporting, thus I was not properly capturing
the exact status location where the error occurred!  duh!

Your example showed me the way!

Thanks!
Dan

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux