I am trying to set up an alias in my .bashrc file like the below:
clear && printf '\033[3J'
But the following does not work
alias clall= "clear && printf \'\033[3J\'"
alias clall= "clear \&\& printf \'\\033\[3J\'"
I am trying to set up an alias in my .bashrc file like the below:
clear && printf '\033[3J'
But the following does not work
alias clall= "clear && printf \'\033[3J\'"
alias clall= "clear \&\& printf \'\\033\[3J\'"
The general rule about aliases is that if you have a question about how to use them (or whether they're capable enough for your purpose), you should be using a function instead. A function gives you all the capability (considerably more, for that matter), and doesn't require any quoting/escaping syntax:
clall() { clear && printf '\033[3J'; }
That said, one way to specify the alias you want is the following bash-extended syntax:
# use $'' to make \' and '' valid/meaningful
alias clall=$'clear && printf \'\\033[3J\''
...which uses $''
to allow single-quotes (and backslashes) to be escaped within single-quotes; under normal ''
quoting, contained backslashes are literal. A more POSIX-y approach is:
# use '"'"' to put a literal single-quote inside syntactic single-quotes
alias clall='clear && printf '"'"'\033[3J'"'"''
...or, if (as here) you don't have any syntax that's special inside double quotes:
# ...or just use double quotes for the whole thing, absent a reason not to
# ...using command substitution, paramater expansion, etc. would be such a reason.
alias clall="clear && printf '\033[3J'"