Re: strange shell behavior...thoughts?

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

 




Gordon Messmer wrote:
> Kevin Martin wrote:
>>
>>> | sh-3.2$ /bin/ksh -c " set -xv  ; grep ABCD  b ; echo $? ; if [ "$?" =
>>> | "0" ] ; then echo yes ; fi"
>>
>> What I've been seeing is if I try to pass the
>> "/bin/ksh -c "if...."" script the $? of the grep never seems to be 0 for
>> some reason so I essentially get the results that I showed in my example
>> where I was doing the dumb "unset $?" (making, at that point, $? =
>> 1). I agree that the "if some_command" would be a much better way of
>> doing
>> this but I get the same results if I do that as I do if I do the
>> "some_command" the "if [ $? = 0 ]" test.  From reading the man page for
>> ksh I may be running into a POSIX vs non-POSIX issue.
>
> Can you share what you see when you use the "if some_command" form?
>
> $ /bin/ksh -c 'grep ABCD b ; if [ "$?" = "0" ] ; then echo yes ; fi'
>
> $ /bin/ksh -c 'grep ABCD b && echo yes'
>
> $ /bin/ksh -c 'if grep ABCD b ; then echo yes ; fi'
>
> All of the above forms work here when I test them.
>
> Your original test has two flaws:
> 1) You're not quoting the $ sign properly, so $? gets expanded by your
> shell, before being passed as an argument to ksh.
> 2) "echo" would set a new value for $? if you did quote it properly,
> so that the value will always be 0 in the "if" test.  (which Cameron
> pointed out, and I completely ignored. ;)
>
> It's not a POSIX issue.
>
Finally got around it with this:

/bin/ksh -c ' export ABCD="a" ;  . ./b ; if [  "$ABCD" != "a" ] ; then
$ABCD/myscript -s -m=1; else $EFGH/myscript -s -m=1 ; fi'

It turned out that using '' around the 'command' portion of the ksh -c
was my answer instead of the ""'s.  I had also tried this:

/bin/ksh -c ' export ABCD="" ;  . ./b ; if [  -n $ABCD ] ; then
$ABCD/myscript -s -m=1; else $EFGH/myscript -s -m=1 ; fi'

but this didn't work either until I just now realized that the  [ -n
$ABCD ] needs to be [ -n "$ABCD" ] (duh again!).

It's amazing when you have other smart people throwing ideas at you how
your brain shifts into different areas of thought and suddenly
inspirations of enlightenment hit you!

Thanks all for your help...truly, 20 heads are better than one!

Kevin

-- 
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