Below I run what I expected to be an invalid command: var=3 date
, which in fact isn't.
$ var=3 date
Sun May 26 17:10:22 UTC 2019
$ echo $?
0
But the variable wasn't assigned the value 3
:
$ echo $var
$
I expected to say that var=3
wasn't a valid command. What am I missing?
man dash
, seeSimple Commands
section. – Arkadiusz Drabczyk May 26 '19 at 17:49compgen -v
gives us completion options of variables. Runningvar=3 compgen -v
won't displayvar
. – Damn Spaces May 26 '19 at 18:03echo $var
in a separate script calledtest.sh
and callingvar=3 ./test.sh
.compgen
is a builtin. Or, even better, putcompgen -v
in that script and you will see var pop up. – Edward May 26 '19 at 18:18