Table of Contents
This tip is about the how to Use the Linux set command. So read this free guide, How to Use the Linux set command step by step. If you have query related to same article you may contact us.
How to Use the Linux set command – Guide
The Linux set command is an implicit shell command that allows you to show or set shell and weather factors. In that guide, we cover the set command and show you the different ways the command line utility can be used.
Syntax
Bourne shell (sh):
to define [–aefhkntuvx[argument]]…
C shell (csh):
to define [var[=value]]
define var [n] = word
Shell Korn (ksh):
to define [+-aefhkmnopstuvx] [+-o option]… [+-A name] [arg…]
Options: Bourne Shell (sh)
In sh, the set built-in command has the following options:
– A double dash option (“-“) means the end of a list of options. This option is especially useful when the values listed after the options begin with a dash themselves.-a Mark variables that are modified or created for “export”; environment variables set in this way will be passed to the environments from any subsequent commands.-e Quit immediately if a command exits with a non-zero exit status.-f Disable filename generation (globbing) .-h Find and remember function commands how functions are defined (function commands are usually found when the function is executed) .- k All keyword arguments are placed in the environment for a command, not just those that precede the command name .-n Read commands but do not execute them .-t Exit after reading and executing a command.-u Treat undefined variables as an error when replacing them.-v Print shell input lines à as they are read. -x Print commands and their arguments as they are executed.
Using + instead of – causes these flags to be turned off. These flags can also be used in calling the shell itself. The current set of flags is found in the $ – variable. The remaining arguments are positional parameters and are assigned, in order, to $1, $2, etc. If no arguments are given, values for all names are printed.
For each name, the unset command removes the corresponding variable or function value. Special variables PATH, PS1, PS2, MAILCHECK and IF cannot be deselected.
With the built-in export command, the given names are marked for automatic export to the environment of subsequently executed commands. If no arguments are given, the names of variables marked for export during current shell execution are listed. Function names are not exported.
Options: C Shell (csh)
In csh, if no arguments are specified, set displays the values of all shell variables. Values for multiple words are displayed as a list in parentheses. With the var argument alone, set assigns an empty (null) value to the var variable. With arguments of the form var = value, set assigns value to var, where value is one of:
word A single word (or string enclosed in quotes). (word list) A list of words placed in parentheses.
Values are the command and filename expanded before being assigned. The var formset[n]= word replaces the nth word in a value of several words per word.
unset removes variables whose names match the pattern (using filename substitution). All variables are removed by “unset *”; however, it’s a bad idea if you don’t know what you’re doing.
Options: K Shell (ksh) In ksh, the set command takes the following options:
-An array assignment. Remove the variable name and assign values sequentially from the arg list. If + A is used, the variable name is not unconfigured first.-a All subsequent variables that are set are automatically exported.-e If a command has a non-zero exit status, run the ERR trap (if configured) and exit . This mode is disabled when reading profiles.-f Disable filename generation (globbing) .-h Each command becomes a traced alias when first encountered.-k All variable assignment arguments are placed in environment for a command, not just those preceding the command name. -m Background jobs run in a separate process group and a line is printed upon completion. The exit status of background jobs is reported in a completion message. On systems with task control, this flag is automatically enabled for interactive shells.-n Read the commands and check for syntax errors, but do not execute them. Ignored for interactive shells.
o option The option argument can be one of the following: allexport Same as -a.errexit Same as -e.bgnice All background jobs run with a lower priority, which is the default mode. -line editor for command entry.emacs Puts you in a gmacs style inline editor for the entry.ignoreeof command Shell will not exit on final of the file. The command output should be used.keyword Equal to -k.markdirs All directory names resulting from filename generation have a “/” final appended.monitor Equal to -m.noclobber Prevent redirect “>” from truncating existing files. Requires “> |” to truncate a file when linked.noexec Same as -n.noglob Same as -f.nolog Don’t save function definitions in the history file.nounset Same as -u.privileged Same as -p.verbose Same as -v.trackall Even as -h.vi Puts you into insert mode of a vi-style inline editor until you click escape. This option argument puts you in control mode. A return sends the line.viraw Each character is processed as it is typed into vi mode.xtrace Same as -x. If no option name is given, the current option settings are printed. -P Disables processing of $ HOME / .profile and uses / etc / suid_profile file instead of ENV file. This mode is enabled whenever the effective uid (user ID) is not the same as the real uid, or when the effective gid (group ID) is not the same as the real gid. Turning this off causes the effective uid and gid to be set to the actual uid and gid.-S Sort positional parameters lexicographically.-t Exits after reading and executing a command.-u Treat undefined parameters as an error when replacing them .-v Print shell input lines as they are read.-x Print commands and their arguments as they are executed.– Disable flags -x and -ve stops examining flag arguments.– Do not change any of the flags. flags; useful for setting $1 to a value starting with -. If no arguments follow this flag, positional parameters will not be set.
Final note
I hope you like the guide How to Use the Linux set command. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.