Quantcast
Channel: What is the difference between $* and $@? - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 12

Answer by Sonia Hamilton for What is the difference between $* and $@?

$
0
0

"$*" has few uses, the other answers cover why.

Here's a neat example of using "$*" to just "print everything" when doing error handling:

error () {  printf '%s\n'"$*"  exit 1}

This script demonstrates the difference:

% cat foo.sh #!/usr/bin/env basherror1 () {  printf '%s\n'"$*"  #exit 1}error2 () {  printf '%s\n'"$@"  #exit 1}error1 "aa" "bb"echo "---"error2 "aa" "bb"
% ./foo.sh  aa bb---aabb

Viewing all articles
Browse latest Browse all 12

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>