6.8k views
4 votes
What does 'set' command do to positional varibales?

User Vdboor
by
6.9k points

1 Answer

5 votes

Final answer:

The 'set' command is used in shell scripting to change the value of positional parameters, allowing scripts to dynamically handle command-line arguments. It assigns values to special variables representing the arguments passed to a script.

Step-by-step explanation:

The 'set' command in shell scripting is used to change the value of positional parameters or to set the positional parameters to the values specified. Positional parameters are special variables that hold the values of command-line arguments that are passed to a script or function when it is called. For instance, $1 refers to the first argument, $2 to the second, and so on.

When the 'set' command is used without any options, it can assign the values after the command to the positional parameters. For example, executing set one two three would assign 'one' to $1, 'two' to $2, and 'three' to $3. This allows a script to dynamically change the values of the arguments it is working with.

Beyond the basic assignment, the 'set' command has a variety of options that can alter its behavior. These include options to enable or disable shell features or to set shell options.

User Wongjn
by
8.0k points