Friday 18 August 2017

Bash Set Bultin

Cited from Bash Positional Parameters Explained with 2 Example Shell Scripts

Set command sets the positional parameter explicitly. Set with the '-' refers end of options, all following arguments are positional parameter even they can begin with '-'. Set with '-' with out any other arguments unset all the positional parameters.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cited from The set builtin command

'-' "End of options" - all following arguments are assigned to the positional parameters, even when they begin with a dash. -x and -v options are turned off. Positional parameters are unchanged (unlike using --!) when no further arguments are given.
'--' If no arguments follow, the positional parameters are unset. With arguments, the positional parameters are set, even if the strings begin with a - (dash) like an option.

## after word splitting each element becomes a parameter
set -- $1

No comments:

Post a Comment