by chubot · 4y ago · 0 comments
Shell functions have all the same functionality as aliases and they'll catch more syntax errors upon "source myscript". Example:
ls() {
command ls --color=auto "$@"
}
is equivalent to alias ls='ls --color=auto'
but IMO less error prone. You also get syntax highlighting.The only tricky thing is to remember the 'command' prefix if the "alias" has the same name as the command. Otherwise you'll get an infinite loop of the function trying to call itself!
In practice
alias 'lspy=ls *.py'
seems to be interchangeable with lspy() {
ls *.py "$@"
}You can make it an alias of * , / etc, so ...
$ * 4 6
24
$
It would keep it's own stack, but let a persistent process do the actual maths.The persistent process could almost any repl of python, ruby etc.
Or use a 'real' calculator like Pike's ivy; https://aplwiki.com/wiki/Ivy
[ is a valid function name tho so fun could be had there.
So you could use = to start the calc, and use infix or postfix notation.
$ function ls () {
> echo denied
> }
$ ls
denied
$ \ls
denied