You should use " $@ " (quotation marks are important) instead of $* in your shell function; it will save the positional parameters exactly as they will be included in the function call.
function keys { tmux send-keys -t work:1 " $@ " }
With " $@ " final command will receive four source arguments:
tmux send-keys -t work:1 'pwd' 'cm' 'ls -latr' 'cm'
Instead of five of the unquoted $* :
tmux send-keys -t work:1 pwd cm ls -latr cm
Or one of the "$*" :
tmux send-keys -t work:1 'pwd cm ls -latr cm'
If incorrect, $* and $@ virtually identical, but they are significantly different if not in double quotes.
$* and $@ are like $1 $2 $3 β¦
The resulting values ββare subject to word splitting and file extension (aka globbing), so you usually do not want to use these (or any other parameter extensions) without double quotes.
Extra word splitting is why your "ls -ltr" (one key argument) becomes ls -ltr (two tmux send-keys arguments).
"$*" is like "$1 $2 $3β¦"
All values ββof positional parameters are combined into one word (string), which is protected from further splitting and globalization of words.
The character that fits between each value of the positional parameter is actually the first character from IFS; this is usually a simple space.
" $@ " is like "$1" "$2" "$3" β¦
Each positional parameter is expanded into a separate word, and they are protected from further splitting and globalization of words.
source share