Accessing bash command line args $@ vs $*

后端 未结 5 1922
孤城傲影
孤城傲影 2020-11-22 13:54

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 \"y         


        
5条回答
  •  渐次进展
    2020-11-22 14:19

    A nice handy overview table from the Bash Hackers Wiki:

    $* versus $@ table

    where c in the third row is the first character of $IFS, the Internal Field Separator, a shell variable.

    If the arguments are to be stored in a script variable and the arguments are expected to contain spaces, I wholeheartedly recommend employing a "$*" trick with the internal field separator $IFS set to tab.

提交回复
热议问题