1

I can run command on ubuntu:

free | grep Mem | awk '{print $3/$2 * 100.0}'

And get result:

20.1092

But when I try to put it in alias:

alias memTotal="free | grep Mem | awk '{print $3/$2 * 100.0}'"

It don't work:

$ memTotal
awk: line 1: runaway regular expression / * 100.0} ...
  • Use a function. No worrying about quotes. – muru Sep 3 '14 at 4:04
2

Try

alias memTotal='free | grep Mem | awk '\''{print $3/$2 * 100.0}'\'

Breaking down the quoting, that's

'free | grep Mem | awk '

followed by an escaped single quote \', then the quoted awk expression '{print $3/$2 * 100.0}' and finally the escaped literal closing quote \'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.