set

From Initq

Jump to: navigation, search

set displays many options relating to bash.

[alibaba@ohnonono ~]$ set
BASH=/bin/bash
BASH_ARGC=()
BASH_ARGV=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="3" [1]="1" [2]="17" [3]="1" [4]="release" [5]="i686-redhat-linux-gnu")
BASH_VERSION='3.1.17(1)-release'
COLORS=/etc/DIR_COLORS.xterm
COLUMNS=104
CVS_RSH=ssh
DIRSTACK=()
EUID=501
GROUPS=()
G_BROKEN_FILENAMES=1
HISTFILE=/home/alibaba/.bash_history
HISTFILESIZE=1000
HISTSIZE=1000
HOME=/home/alibaba
HOSTNAME=ohnonono.com
HOSTTYPE=i686
IFS=$' \t\n'
INPUTRC=/etc/inputrc
LANG=en_US.UTF-8
LESSOPEN='|/usr/bin/lesspipe.sh %s'
LINES=24
LOGNAME=alibaba
MACHTYPE=i686-redhat-linux-gnu
MAIL=/var/spool/mail/alibaba
MAILCHECK=60
OPTERR=1
OPTIND=1
OSTYPE=linux-gnu
PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/alibaba/bin
PIPESTATUS=([0]="0" [1]="0")
PPID=15202
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
PS1='[\u@\h \W]\$ '
PS2='> '
PS4='+ '
PWD=/home/alibaba
SHELL=/bin/bash
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
SHLVL=1
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
SSH_CLIENT='192.168.0.7 4753 22'
SSH_CONNECTION='192.168.0.7 4753 192.168.0.10 22'
SSH_TTY=/dev/pts/1
TERM=xterm
UID=501
USER=alibaba
_=
consoletype=pty

set

Manipulate shell variables and functions.

Syntax

     set [--abBCefhHkmnpPtuvx] [-o option] [argument ...]

If no options or arguments are supplied, set displays the names and values of all shell variables and functions, sorted according to the current locale, in a format that may be reused as input. When options are supplied, they set or unset shell attributes.

Options

Using `+' rather than `-' will cause the option to be turned off.

-a allexport

         Mark variables which are modified or created for export.      

-b notify

         Cause the status of terminated background jobs to be 
         reported immediately, rather than before printing the
         next primary prompt. 
   

-B braceexpand

         The shell will perform brace expansion. 
         This option is on by default. 

-C noclobber

         Prevent output redirection using `>', `>&',
         and `<>' from overwriting existing files. 

-e errexit

         Exit immediately if a simple command exits with a non-zero
         status, unless the command that fails is part of an until or
         while loop, part of an if statement, part of a && or || list,
         or if the command's return status is being inverted using !. 

-f noglob

         Disable file name generation (globbing). 

-h hashall

         Locate and remember (hash) commands as they are looked
         up for execution. This option is enabled by default.

-H histexpand

         Enable `!' style history substitution 
         This option is on by default for interactive shells. 

-k keyword

         All arguments in the form of assignment statements are
         placed in the environment for a command, not just those that
         precede the command name.

-m monitor

         Job control is enabled. 

-n noexec

         Read commands but do not execute them; this may be used
         to check a script for syntax errors. 
         This option is ignored by interactive shells. 

-o option-name

         Set the option corresponding to `option-name'
         The `option-names' are listed above and below (in ITALICS)      
         emacs     : Use an emacs-style line editing interface . 
         history   : Enable command history,
                     this option is on by default in interactive shells. 
         ignoreeof : An interactive shell will not exit upon reading EOF. 
         posix     : Change the behavior of Bash to match the POSIX 1003.2 standard. 
         vi        : Use a vi-style line editing interface. 

-p privileged

         Turn on privileged mode. In this mode,
         the $BASH_ENV and $ENV files are not processed,
         shell functions are not inherited from the environment, 
         and the SHELLOPTS variable, if it appears in the environment, 
         is ignored. 
         If the shell is started with the effective user (group) id 
         not equal to the real user (group) id, and the -p option 
         is not supplied, these actions are taken and the effective 
         user id is set to the real user id. 
         If the -p option is supplied at startup, the effective user 
         id is not reset. Turning this option off causes the effective 
         user and group ids to be set to the real user and group ids. 

-P physical

         If set, do not follow symbolic links when performing 
         commands. The physical directory is used instead. 

-t onecmd

         Exit after reading and executing one command. 

-u nounset

         Treat unset variables as an error when performing 
         parameter expansion. An error message will be written 
         to the standard error, and a non-interactive shell will exit.

-v verbose

         Print shell input lines as they are read. 

-x xtrace

         Print a trace of simple commands and their arguments
         after they are expanded and before they are executed. 
 

--

   If no arguments follow this option, then the positional parameters are unset. 
   Otherwise, the positional parameters are set to the arguments, 
   even if some of them begin with a `-'. 

-

   Signal the end of options, cause all remaining arguments to be 
   assigned to the positional parameters. The `-x' and `-v' 
   options are turned off. If there are no arguments, the positional parameters 
   remain unchanged.

Examples

Set the variable 'mydept' equal to 'Sales' :

mydept=Sales

To make the change permanent:

export mydept

Symbolic Links

By default, Bash follows the logical chain of directories when performing commands which change the current directory. e.g.

If `/usr/sys' is a symbolic link to `/usr/local/sys' then:

$ cd /usr/sys; echo $PWD /usr/sys $ cd ..; pwd /usr

   If set -P is on (do not follow symbolic links), then: 

$ cd /usr/sys; echo $PWD /usr/local/sys $ cd ..; pwd /usr/local

Debugging part of a script:

set -x # activate debugging

  1. your commands go here...

set +x # stop debugging

The options can also be used upon invocation of the shell. The current set of options may be found in $-. The remaining N arguments are positional parameters and are assigned, in order, to $1, $2, ... $N. The special parameter # is set to N.

set is a POSIX `special' builtin. The return status is always zero unless an invalid option is supplied.

Personal tools