set Command in Linux
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
Overview
Linux is a robust operating system, offering a variety of tools for efficient and flexible system administration. Among these tools, the 'set' command in Linux holds a significant position. It is a built-in command of the Bash shell used to set and unset certain flags or settings within the shell environment. Understanding the 'set' command in Linux can significantly improve your command-line efficiency and allow you to better control your working environment.
Syntax of set Command in Linux
The basic syntax of the set command in Linux is as follows:
Where:
- options: These are the flags that alter the behavior of the 'set' command. Examples include '-o', '-f', '-u', etc.
- name=value: This is the key-value pair used for setting shell options. The name refers to the option you want to set, and value is the value you want to assign.
Options in set Command in Linux
-
-o: This option allows you to control shell options using a long name instead of a single character.
For example -
This prevents existing files from being overwritten when using the redirection operator '>'.
-
-f: This option disables filename expansion (globbing).
For example -
After this command, wildcard characters will not be replaced by filenames.
-
+o: This option is used to unset an option using its long name.
For example -
This allows existing files to be overwritten when using the redirection operator '>'.
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Example Usages
-
Using 'set' to view all shell variables and functions:
Output:
Explanation: This usage of 'set' without any option or argument will list all the shell variables and functions.
-
Setting shell option 'ignoreeof' using 'set':
Explanation: This prevents the shell from exiting upon receiving an EOF character.
Tips
-
You can use 'set -' to revert to default settings.
-
You can use 'set --' to mark the end of options and disable further option processing.
Turn Learning into Career Growth
Advanced Use Cases of set Command in Linux
-
Setting positional parameters using 'set':
Explanation: This will set the positional parameters. Here, '2' will be 'b', and '$3' will be 'c'.
-
Using 'set' to enable debugging:
Explanation: This will print each command to the standard error before executing it, which is useful for debugging scripts.
-
Using 'set' to protect against script modification:
Explanation: This is an advanced usage where 'set' helps in preventing scripts from accidental overwriting.
Conclusion
-
The 'set' command in Linux is a powerful built-in command of the Bash shell.
-
It allows you to control shell options and set positional parameters.
-
Advanced use of 'set' can enhance your scripting efficiency and protect your scripts.




