Accessing bash command line args $@ vs $*
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In many SO questions and bash tutorials I see that I can access command line args in bash scripts in two ways: $ ~ >cat testargs.sh #!/bin/bash echo "you passed me" $* echo "you passed me" $@ Which results in: $ ~> bash testargs.sh arg1 arg2 you passed me arg1 arg2 you passed me arg1 arg2 What is the difference between $* and $@ ? When should one use the former and when shall one use the latter? 回答1: The difference appears when the special parameters are quoted. Let me illustrate the differences: $ set -- "arg 1" "arg 2" "arg 3" $ for word