Linux Set Command
Linux set command is used to set and unset certain flags or settings within the shell environment. These flags and settings determine the behavior of a defined script and help in executing the tasks without facing any issue. The values of shell attributes and parameters can be changed or displayed by using the set command.
Options: The supported options by the set command are as following:
Note: To turn off the above flags, use the '+' rather than '-' symbol.
To better understand the set command, let's see a brief introduction of the shell variable:
A variable is a character string that can hold a value. The assigned value could be anything such as number, filename, text, or any other data type. It is just like a pointer to the actual data. The shell allows us to create, delete, and assign variables.
The variable name can have any letters, numbers, or underscore (_) character. We cannot have the characters such as "! *, or -", because these special characters have other meanings for the shell. According to Unix naming convention, the Unix shell variable must have their names in UPPERCASE.
Examples of the set command
Turn debugging information on or off.
The '-x' option is used with the set command to show command and their arguments. It is useful for debugging the shell script.
Execute the following command:
To turn on the debugging information:
To turn off the debugging information:
Disable Bash's default behavior.
To disable the default behavior of Bash, execute the command as follows:
Stop a script immediately.
To stop a script immediately, execute the following command:
If you get stuck during the use of the set command, you can access the help documentation from your terminal. To access the help manual, execute the below command: