set Command in Linux

Learn via video courses
Topics Covered

Build an AI-First Career, Master the Complete Skillset

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program
NSDC Certified

AI Forward Deployed Engineer Program

Full-stack engineering, production AI and client-facing consulting

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program

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.
Sharpen Your Fundamentals with Free Learning

Options in set Command in Linux

  1. -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 '>'.

  2. -f: This option disables filename expansion (globbing).

    For example -

    After this command, wildcard characters will not be replaced by filenames.

  3. +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 '>'.

How Scaler Transformed Careers in Different Fields

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

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

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Advanced Use Cases of set Command in Linux

  • Setting positional parameters using 'set':

    Explanation: This will set the positional parameters. Here, '1willbea,1' will be 'a', '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.