0

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.

2
  • You can get by $1, $2, etc... for first, second, ... arguments. Commented Jan 2, 2017 at 0:26
  • Also look for bash getopts for named arguments. Commented Jan 2, 2017 at 0:27

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.