help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] confused by command substitution...


From: Andy Chu
Subject: Re: [Help-bash] confused by command substitution...
Date: Sat, 9 Feb 2019 10:12:50 -0800

This doesn't have to do with command subs, or even if statements.  The way
I think of it is that a command line can evaluate to an empty argv array
after splitting ("elision"), and then that empty argv array silently
*succeeds*.

Consider these commands, and note:

1) The only difference is quotes around $x
2) There are no command subs involved.


x=''

$ ( exit 42; ); echo status=$?; $x; echo status=$?
status=42
status=0


$ ( exit 42; ); echo status=$?; "$x"; echo status=$?
status=42
: command not found
status=127





On Sat, Feb 9, 2019 at 7:05 AM Alfred M. Szmidt <address@hidden> wrote:

> I'm not understanding the difference here, or why the last example
> works.  Anyone got a good explanation?
>
> $ if "$(echo x)"; then echo foo; fi
> bash: x: command not found
> $ if "$(echo x > /dev/null)"; then echo foo; fi
> bash: : command not found
> $ if $(echo x); then echo foo; fi
> bash: x: command not found
> $ if $(echo x > /dev/null); then echo foo; fi
> foo
> $
>
>


reply via email to

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