Just add an echo command in your alias before the actual command:
alias ls='echo "Running ls -alh"; ls -alh'
سؤال
I am trying to get alias's setup so that they print out the command, then run the command.
Ex:
> alias ls='ls -alh'
> ls
Running "ls -alh"
total 1.8G
drwxr-x--- 36 root root 4.0K Apr 23 09:44 ./
drwxr-xr-x 28 root root 4.0K Mar 6 17:24 ../
Is this possible? I was thinking of using a wrapper function, but I am unsure as to how one would acomplish this.
Thanks!
المحلول
Just add an echo command in your alias before the actual command:
alias ls='echo "Running ls -alh"; ls -alh'
نصائح أخرى
alias ls='echo "Running ls -alh" && ls -alh'
This runs two commands one after the other. The first command is echo "Running ls -alh"
, the &&
checks the return value of the echo command, if that's 0
, then the command ls -alh
is run. However, if for some reason there is a problem with the echo
command and its return value is not 0
then the ls
command won't be run.
The &&
command can come in very handy when writing scripts to run one command only when another is successful.