Re: /bin/sh -e function parsing strangeness

From: Vasil Dimov (vd_at_datamax.bg)
Date: 06/26/05

  • Next message: Dmitry Mityugov: "Re: KMEM Problem With OIDENTD"
    Date: Sun, 26 Jun 2005 12:00:25 +0300
    To: hackers@freebsd.org
    
    

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    On Sun, Jun 26, 2005 at 11:27:02AM +0300, Vasil Dimov wrote:
    >
    > Can anyone explain this:
    >
    > % sh -ec 'f() { return 5 ; } ; if f ; then echo tt ; else echo ff ; fi'
    > ff
    > % sh -ec 'f() { return 5 ; : ; } ; if f ; then echo tt ; else echo ff ; fi'
    > % echo $?
    > 5
    >
    > If any commands appear after the return statement in a function,
    > then -e flag triggers untested command failure although function call is
    > tested with `if' statement.
    >

    I see, -e counts for each command inside function body, no matter that
    the whole function return status is tested with `if'.

    % sh -ec 'f() { ls /nonexistent ; ls / ; } ; if f ; then echo tt ; else echo ff ; fi'
    ls: /nonexistent: No such file or directory
    %

    Probably this should be considered as a sh "feature".

    -----BEGIN PGP SIGNATURE-----

    iD8DBQFCvm6pFw6SP/bBpCARAu6FAKCCoGXwounURHk6o4m8huqEDtmX9wCfXqxf
    M0BT7Ej0fG9Iulgr/A18MMk=
    =/5jF
    -----END PGP SIGNATURE-----
    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


  • Next message: Dmitry Mityugov: "Re: KMEM Problem With OIDENTD"

    Relevant Pages

    • Re: [opensuse] Undelete
      ... Hash: SHA1 ... How do i recover some files that were ... I ran the rm from the command line and using reiser. ...
      (SuSE)
    • Re: mtab
      ... Hash: SHA1 ... > With the mountcommand? ... To unsubscribe, ...
      (freebsd-questions)
    • Re: 8139too again!
      ... Hash: SHA1 ... >> No, you gave the command the IO parameter, which is not valid for that ... Automatic actions for USB cameras, cardreaders, memory sticks, MP3 players ...
      (Fedora)
    • Re: rpm question
      ... Hash: SHA1 ... > Entered the command and nothing happened for 10 minutes and it seemed my session had locked up, ...
      (RedHat)
    • Re: [SLE] Why wont 9.3 see my DVD-RAM drive
      ... Hash: SHA1 ... the mount directory is created on the fly with the same ... And try with the command "lshal". ...
      (SuSE)