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 "$@"
} $ function ls () {
> echo denied
> }
$ ls
denied
$ \ls
deniedFor commands I use frequently or that are clunky to maintain as one-liners, I'll convert them into functions in my bashrc.
This seems like the best of both worlds in many ways, or at least is a great third option to have.
> I log shell commands with a script called usrlog.sh that creates [per-]$USER and per-virtualenv tab-delimited [$_USRLOG] logfiles with unique per-terminal-session identifiers [$_TERM_ID] and ISO8601 timestamps; so it's really easy to just grep for the apt/yum/dnf commands that I ran ad-hoc when I should've just taken a second to create an Ansible role with `ansible-galaxy init ansible-role-name ` and referenced that in a consolidated system playbook with a `when` clause. https://westurner.github.io/dotfiles/usrlog.html#usrlog
stid \#tutorial; echo "$_TERM_ID"
tail -n11 $_USRLOG
ut -n11
grep "$_TERM_ID" "$_USRLOG"
usrlog_grep "$_TERM_ID"
ug "$_TERM_ID"
usrlog_grep_parse "$_TERM_ID"
ugp "$_TERM_ID" # `type ugp`
usrlog.sh: https://github.com/westurner/dotfiles/blob/master/scripts/us...The mnemonic is erc=edit rc, src=source rc.
alias erc="vim ~/.bash_aliases" alias src="source ~/.bash_aliases"
Whenever I need to add or modify some shell function or alias (or even make a quick note) I type erc to open the alias file. Then I type src to load it. Very handy.
http://www.modernperlbooks.com/mt/2009/10/remove-the-little-...
hack hack, then run
nuscript-bash something
Hit C-x C-h, select some lines, edit, then run something
To do maintenance: edcom something
I wrote a little more about it here: https://blag.felixhummel.de/basics/bash/wrapper-scripts.html