Hello! Before I begin, my question is not a duplicate of this: https://askubuntu.com/questions/1071263/multi-line-alias-in-bash or this: Multiple commands in an alias for bash. And I've read the answers thoroughly.
My issue is that when I assign a variable inside a multi-line alias, something goes wrong in which it causes the shell to wait for another argument.
Here's a working alias:
$ alias alias1='var1="$(date)" ; echo $var1'
Wed Jul 28 18:07:37 +0230 2021
But if I write it in multiple lines, shell waits for another argument:
$ alias alias1='var1="$(date)"
> echo $var1'
$ alias1
$ hello
Wed Jul 28 18:10:28 +0230 2021 hello
I know the issue is with date
but I don't understand what is happening.
I tried putting ;
at the end of the first line, and it didn't fix the issue, but I put &&
and it fixed the issue, \
also fixed the issue which is weird to me because \
is for line continuation:
$ alias alias1='var1="$(date)" \
echo $var1'
$ alias1
Wed Jul 28 18:12:47 +0230 2021
Thanks in advance.