foo=barYou can check the value of the variable with:
echo $fooFor a variable to be an environment variable it must be exported. You can define it and then export it like this:
foo=bar boo=woo export foo booOr you can save yourself some typing by doing it like this:
export foo=bar export boo=wooSummary of bash variables
You can also have certain types of file excluded from the file name completion mechanism. Set the FIGNORE environment variable to a colon separated list of the file name suffixes you want ignored. See the example ~/.bash_profile below.
alias ll='ls -lF'To remove the previously defined alias, use...
unalias llWarning: unlike csh, bash aliases do not accept parameters. If you have aliases that use parameters you can change them to simple functions. For and example have a look in the annotated .bashrc below, or just read the next section. :-)
This version replaces the builtin cd with one that prints out the current directory after the directory is changed. You can define any number of functions either directly at the command line for temporary ones, or add them to your ~/.bashrc file.cd() { builtin cd $1 pwd }
For more information see "Learning the bash shell", page 87.
This file is executed when you first login, the variables are all exported so that they are available to all subshells.
This has a bit of tricky programming in it where all of the paths are stored in separate files - so that they can be easily changed without modifying the original ~/.bash_profile file.
# ~/.bash_profile # Executed by login shells # Converts a \n separated list into a colon separated list colonise() { /bin/cat $1 | /bin/tr "\012" ":" } ### Variables used by bash itself # Paths... # these all use the above "colonise" function to # convert a list of paths on separate lines into # a colon separated list. export PATH=`colonise ~/.path` export MANPATH=`colonise ~/.manpath` export MAILPATH=`colonise ~/.mailpath` export CDPATH=`colonise ~/.cdpath` # Control history # I don't like to have a lot of # old commands hanging around. export HISTFILESIZE=10 export HISTSIZE=10 export HISTCONTROL=ignoreboth # Control file name completion: ignore the following suffixes export FIGNORE=`colonise ~/.fignore` # Exiting bash deliberately and involuntarily # export IGNOREEOF=1 export TMOUT=3600 # Prompt export PS1="[\u@\h] \W [\!] " ### Variables that don't relate to bash # Set variables for a warm fuzzy environment export CVSROOT=~/.cvsroot export PGPPATH=~/.pgp export EDITOR=/usr/local/bin/emacs export PAGER=/usr/local/bin/less export PRINTER=134 # Execute the subshell script source ~/.bashrc # end of ~/.bash_profile
You can also create a ~/.bash_logout file that is executed whenever you log out.# ~/.bashrc # executed by login and subshells # aliases # search man pages by subject alias a='man -k' # edit and re-read this file alias be='$EDITOR ~/.bashrc ; source ~/.bashrc' # add the current directory to the "cdpath" alias cdpath='pwd >> ~/.cdpath ; export CDPATH=`colonise ~/.cdpath`' # abbreviations for some common commands alias f=finger alias h=history alias j=jobs alias l='ls -lF' alias la='ls -alF' alias lo=logout alias ls='ls -F' alias m='less -a -i -P=' alias weather='telnet vicbeta.vic.bom.gov.au 55555' alias which='type -all' alias xman='xman -bothshown -notopbox &' # functions # A new version of "cd" which # prints the directory after cd'ing cd() { builtin cd $1 pwd } # add the directoried specified to the path file # and re-read it. pathadd() { for p in $* do echo $p >> ~/.path done export PATH=`colonise ~/.path` } # Other settings umask 027 mesg y # end of ~/.bashrc # Uncomment the following if you prefer vi style command editing # to emacs style # set +o emacs # set -o vi # Important startup procedures... /usr/local/games/bin/fortune echo # end of ~/.bashrc