Search code examples
bashpositional-parameter

Bash get variable at shell execution


There is a method to get a variable with the bash execution command?

Example:

./exec.sh var1 var2

or with arguments

./exec.sh -x var1 -y var2

I looked for "Get variable at bash execution" but nothing.


Solution

  • As the comment mentions, $1, $2, etc are positional variables for the arguments. But there are lots more, very useful ones too like $# for the number of arguments passed, etc. More info at

    http://wiki.bash-hackers.org/syntax/shellvars