Ubuntu – Which character to escape for this to work in ~/.bashrc

bashbashrccommand line

I want to add this iostat command to my .bashrc and create an alias for it:

iostat -xk 2 $(findmnt -T ~ | awk 'END {print $2}')

I'm adding this to my .bashrc:

alias ios='iostat -xk 2 $(findmnt -T ~ | awk 'END {print $2}')'

Unfortunately, it doesn't work.

If I run the above iostat command in a terminal it works, but when I run the ios alias it no longer works.

And yes, I restart my shell every time.

Best Answer

Use a function instead; the quoting is simpler:

ios () {
  iostat -xk 2 $(findmnt -T ~ | awk 'END {print $2}')
}
Related Question