1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Discuss in my forum

The Bash set Command

Description and Examples

By

See More About

Introduction

The behavior of a Linux shell is determined by the shell program used, e.g., bash, and the variables that are accessible in that shell. The set of variables set in a particular session is referred to as the "environment", and the variables that constitute this environment are called "environment variables".

Many programs make implicit use of the environment variables. Perhaps the most important environment variable is the "Path", which is assigned a list of directory paths that the shell searches when it is instructed to execute a command or program.

Besides environment variables that are accessible by other programs, there are "shell options" that can be used to change the properties of the shell.

The command to assign a value to a shell option is set. For example to set the editing mode of the command line to vi instead of the default emacs mode, you use:

set -o vi

This enables you to use vi editing commands.

To see a list of all available shell options, use:

set -o

Which will print out:

   allexport          off
   braceexpand        on
   emacs              on
   errexit            off
   errtrace           off
   functrace          off
   hashall            on
   histexpand         on
   history            on
   ignoreeof          off
   interactive-comments    on
   keyword            off
   monitor            on
   noclobber          off
   noexec             off
   noglob             off
   nolog              off
   notify             off
   nounset            off
   onecmd             off
   physical           off
   pipefail           off
   posix              off
   privileged         off
   verbose            off
   vi                 off
   xtrace             off

 

 

Man Page

NAME
    set - Set or unset values of shell options and positional parameters.

SYNOPSIS
    set [--abefhkmnptuvxBCHP] [-o option-name] [arg ...]

DESCRIPTION
    Set or unset values of shell options and positional parameters.

    Change the value of shell attributes and positional parameters, or display the
    names and values of shell variables.

    Options:
      -a  Mark variables which are modified or created for export.
      -b  Notify of job termination immediately.
      -e  Exit immediately if a command exits with a non-zero status.
      -f   Disable file name generation (globbing).
      -h  Remember the location of commands as they are looked up.
      -k  All assignment arguments are placed in the environment for a
           command, not just those that precede the command name.
      -m  Job control is enabled.
      -n  Read commands but do not execute them.
      -o  option-name
          Set the variable corresponding to option-name:
              allexport        same as -a
              braceexpand  same as -B
              emacs          use an emacs-style line editing interface
              errexit           same as -e
              errtrace         same as -E
              functrace       same as -T
              hashall          same as -h
              histexpand    same as -H
              history          enable command history
              ignoreeof      the shell will not exit upon reading EOF
              interactive-comments
                                  allow comments to appear in interactive
                                  commands
              keyword        same as -k
              monitor         same as -m
              noclobber     same as -C
              noexec         same as -n
              noglob          same as -f
              nolog           currently accepted but ignored
              notify           same as -b
              nounset       same as -u
              onecmd       same as -t
              physical       same as -P
              pipefail         the return value of a pipeline is the status of
                                 the last command to exit with a non-zero status,
                                 or zero if no command exited with a non-zero status
              posix           change the behavior of bash where the default
                                 operation differs from the Posix standard to
                                 match the standard
              privileged     same as -p
              verbose       same as -v
              vi                use a vi-style line editing interface
              xtrace          same as -x
      -p  Turned on whenever the real and effective user ids do not match.
           Disables processing of the $ENV file and importing of shell
           functions.  Turning this option off causes the effective uid and
           gid to be set to the real uid and gid.
      -t   Exit after reading and executing one command.
      -u  Treat unset variables as an error when substituting.
      -v  Print shell input lines as they are read.
      -x  Print commands and their arguments as they are executed.
      -B  the shell will perform brace expansion
      -C  If set, disallow existing regular files to be overwritten
           by redirection of output.
      -E  If set, the ERR trap is inherited by shell functions.
      -H  Enable ! style history substitution.  This flag is on
           by default when the shell is interactive.
      -P  If set, do not follow symbolic links when executing commands
           such as cd which change the current directory.
      -T  If set, the DEBUG trap is inherited by shell functions.
      -    Assign any remaining arguments to the positional parameters.
           The -x and -v options are turned off.

    Using + rather than - causes these flags to be turned off.  The
    flags can also be used upon invocation of the shell.  The current
    set of flags may be found in $-.  The remaining n ARGs are positional
    parameters and are assigned, in order, to $1, $2, .. $n.  If no
    ARGs are given, all shell variables are printed.

    Exit Status:
    Returns success unless an invalid option is given.

 

See Also:

 

Bash Arithmetic

Bash Functions and Subroutines

Bash Conditionals

Bash For-Loops

Bash While-Loops

 

-daystart

Measure times (for -amin, -atime, -cmin, -ctime, -mmin, and -mtime) from the beginning of today rather than from 24 hours ago.

-daystart

Measure times (for -amin, -atime, -cmin, -ctime, -mmin, and -mtime) from the beginning of today rather than from 24 hours ago.

  1. About.com
  2. Technology
  3. Linux
  4. Linux / Shell Commands
  5. The Bash set Command

©2014 About.com. All rights reserved.