Is it possible to make a shortcut for a bash command that will also include variables?

Solution 1:

There is a middle way, using functions. In your .bashrc, you could define a function to do this:

tarbp() {
  input=$1
  output=$2
  tar cf - /"${input}" -P | pv -s "$(du -sb /"${input}" | awk '{print $1}')" | gzip > "${output}".tar.gz
}

$1 and $2 are the first and second parameter passed to the function.

After restarting your shell (or reloading your .bashrc), you can use the function like a regular command:

tarbp input output

(Ubuntu even does bash completion on this)