In the example you mention, where the expansion for the alias is a single word containing no character that is subject to expansion, it makes no difference how you quote the name _cutf
:
$ alias cutf="_cutf"
$ alias cutf
alias cutf='_cutf'
$ unalias cutf
$ alias cutf='_cutf'
$ alias cutf
alias cutf='_cutf'
$ unalias cutf
$ alias cutf=_cutf
$ alias cutf
alias cutf='_cutf'
As you can see in that interaction, recalling the value of the alias cutf
gave the same result each time. So, yes, the quoting styles are interchangeable here.
It is not relevant that the expansion is to a function name: at least with bash, aliases perform a simple textual substitution (it is not obvious to me in what way defining an alias is useful; directly calling the underlying function seems just as easy).
Single-quote vs double-quote versions
Let's define the alias using single-quotes:
$ alias d='$(date)'
Now, let's retrieve the definition of the alias:
$ alias d
alias d='$(date)'
Observe that no command substitution was yet performed.
Let's do the same, but this time with double-quotes:
$ alias d="$(date)"
$ alias d
alias d='Fri Oct 28 17:01:12 PDT 2016'
Because double-quotes are used, command substitution was performed before the alias was defined.
Single-quote version
Let's try executing the single-quote version:
$ alias d='$(date)'
$ d
bash: Fri: command not found
The single-quote version is equivalent to running:
$ $(date)
bash: Fri: command not found
In both cases, the command substitution is performed when the command is executed.
A variation
Let's consider this alias which uses command substitution and is defined using single-quotes:
$ alias e='echo $(date)'
$ e
Fri Oct 28 17:05:29 PDT 2016
$ e
Fri Oct 28 17:05:35 PDT 2016
Every time that we run this command, date
is evaluated again. With single-quotes, the command substitution is performed when the alias is executed, not when it is defined.
Best Answer
Aliases are only expanded as the first argument, or after another alias with a trailing space on the end of the command.
From
bash
'shelp alias
:To do this, try the following:
Bear in mind that some versions of
watch
strip colours by default, on some versions this can be stopped by using--color
or-G
.