Last active
August 15, 2018 09:54
-
-
Save kmsheng/2676cb0339db93add241a91a64cd2f84 to your computer and use it in GitHub Desktop.
All kinds of dollar signs in shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Run this script with dollar-sign.sh a b c | |
echo "process id =" $$ | |
echo | |
echo "how many arguments = $#" | |
echo "arg0, 1, 2, 3 =" $0 $1 $2 $3 | |
echo | |
echo "\$* =" $* | |
echo "\$@ =" $@ | |
echo | |
echo "print each param from \$*" | |
for var in $* | |
do | |
echo "$var" | |
done | |
echo "print each param from \@" | |
for var in $@ | |
do | |
echo "$var" | |
done | |
echo | |
# $* 與 $@ 的差異只有在 $* 被雙引號包住時看得出來 | |
# "$*" 會把所有參數用空白隔開並且顯示在同一行 | |
echo "print each param from \"\$*\"" | |
for var in "$*" | |
do | |
echo "$var" | |
done | |
echo "print each param from \"\@\"" | |
for var in "$@" | |
do | |
echo "$var" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment