A few posts ago someone asked how to show memory in percentage. Someone replied with:
free | awk '/^Mem/ { printf("free: %.2f %\n", $4/$2 * 100.0) }'
I was wondering if I can turn this command into an alias in ~/.bashrc. But the syntax of alias is:
alias aliasname='command'
How can I do this? That command contains both '
and "
. I tried different ways, but it didn't work. Is this even possible? Am I missing something?
aliasname() { free | awk '/^Mem/ { printf("free: %.2f %\n", $4/$2 * 100.0) }'; }
-- still just one line, no changes to quoting/escaping/etc needed at all. There's a reason the freenode #bash channel!alias
factoid is (well, was, but for most of the factoid bot's life some variant of): If you have to ask, use a function instead. – Charles Duffy Dec 30 '18 at 03:51