help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Undocumented caret logical operator?


From: Eric Blake
Subject: Re: [Help-bash] Undocumented caret logical operator?
Date: Wed, 2 May 2018 13:38:15 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

On 05/02/2018 01:09 PM, G. Branden Robinson wrote:
Here's why I asked.  There's a piece of OpenSSH that seems to believe ^
is, or might be, an operator.  It's down in the weeds of some
shell-detection madness, so I'm not sure if they're on crack or not.

https://pastebin.com/df7jYEib

(Pastebins expire, but the mailing list archives do not; copying some of that example here)

# check that we have something mildly sane as our shell, or try to find something better if false ^ printf "%s: WARNING: ancient shell, hunting for a more modern one... " "$0"
then

Yes, on all modern systems (and any POSIXy shell), this executes the single command 'false' with ignored arguments, and skips the 'then' clause. Meanwhile, on old Solaris systems, where /bin/sh is Bourne shell rather than POSIX sh and has a ^ operator, this is parsed the same as 'false | printf ...', which executes the printf command (which may or may not have been a builtin in that old shell, and may or may not be on your PATH); it is HOPING that the exit status of printf will be 0, and that the WARNING message was printed, and that the 'then' clause then gets a chance to try re-execing under a saner shell.

But since printf is a relatively modern shell invention, I'm seriously wondering if a system old enough to have /bin/sh that understands ^ as a pipe operator would also lack printf, and thus break this snippet.

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]