How can I make "and" be a working alias for && in Bash?
I want to be able to use and
instead of &&
in Bash.
I tried alias and=&&
but the behavior is not the same.
steven% echo 'hi' && echo 'bi' (git)-[yako.botrank-rate-limit-status]-
hi
bi
steven% echo 'hi' and echo 'bi'
hi and echo bi
Solution 1:
(this is my first answer on this stackexchange so please bear with me)
The other answer seems to be correct that this is not possible, however as a workaround I have considered the following code because I also wanted to do something like this:
alias and='read and1 && read and2 && eval $and1 && eval $and2'
this post has warnings about using the "eval" command, and some suggestions of what you could use instead that would work as well or better: https://unix.stackexchange.com/questions/444946/how-can-we-run-a-command-stored-in-a-variable
this will allow you to do two commands, one after the other, in a kind of polish notation. So, you would type "and"+enter, type in a command then enter, then the next command and enter, and it would then run each command. (and command command)
you could also chain these together by typing and+enter, then typing the first command then enter, then typing and+enter again (making "and" the second command to execute). (and command (and command command))
Solution 2:
This is not possible in bash.
Bash provides no syntax to override an operator. In other words, all operators and reserved words are hard-coded. Search for yourself in the Bash Reference Manual.
Also note, the Bash Reference Manual: Aliases states, "Aliases allow a string to be substituted for a word when it is used as the first word of a simple command."
Solution 3:
You can use something like AutoKey to create abbreviations.
So for example, typing and[TAB]
will expand to &&
.