I would expect the second line to say foo
instead of command not found
:
$ alias foo=\"echo bac\" ; foo;
-bash: foo: command not fou
To set and use alias
in the same line in bash, you can use:
eval $'alias df5=df\ndf5 -h'
(credits: Hauke Laging's workaround + Kusalananda's workaround).
Explanation of the command:
eval
and place a new line between the alias
definition and its use."The
$'...'
is a "C string", andbash
would expand the\n
within it to a literal newline before passing it toeval
.