I do not understand what happens here.
What I try to achieve:
When I call an alias I would like to have
- output who and where called this, like the CLI does
- output the actually commands behind the alias
- execute the commands behind the alias.
Example:
# The prefix to be re-used.
__PREFIX='$(whoami)@$(hostname):$(pwd)\$'
# The commands to execute in a var to be able to print them too.
FOO="echo 'foo' && echo 1"
BAR="echo 'bar' && echo 2"
BAZ="echo 'baz' && echo 3"
# Define aliases
# echo the prefix and the command that will be executed,
# and the execute the commands.
alias FOO='echo ${__PREFIX}'" '${FOO}' && ${FOO}"
alias BAR='echo ${__PREFIX}'" '${BAR}' && ${BAR}"
alias BAZ='echo ${__PREFIX}'" '${BAZ}' && ${BAZ}"
I found out that I have to use $(pwd)
in single quotes '
to call it and not "print" it into the alias.
The FOO
example above prints:
username@notebook:~$
$(whoami)@$(hostname):$(pwd)\$ echo foo && echo 1
foo
1
When I change the FOO
example to
alias FOO='echo $(whoami)@$(hostname):$(pwd)\$'" '${FOO}' && ${FOO}"
then it works:
username@notebook:~$
username@notebook:/home/username$ echo foo && echo 1
foo
1
Question: how can I have the whoami, hostname and pwd in a var, and then use it in an alias?