Skip to content

Sea shells, sea shells on the sea shore

January 17, 2011

Now that I have had enough of Fallout 3 on the PS3 its time to get back into Linux!

I’ve been learning about Shells…What happens in Linux is that the user inputs instructions/commands into the Shell which in turn interprets them and processes them to the Kernal.

The Kernal then processes the instructions/commands and talks to the appropriate hardware to complete the instruction/command.

The Kernal receives the output of the instruction/command and then processes the output back to the Shell, i.e. where the user is working.

Each Shell has variables, they are broken down into two forms: –

A Local Variable is a variable that can only process variables that have been started in its Shell, i.e. the Bash Shell.

A Environment Variable is a variable that can process commands that have been started in other Shells, i.e. a user may be working in the Bash Shell that has altered the value of a Environment Variable, as this is an Environmental Variable this Variable can be accessed from another Shell, for instance the C Shell.

The most common Shell that is used is the Bash Shell, there are other Shells that are used for other purposes. I believe there is a C Shell which is used for compiling code from the C# language, perhaps this Shell will also have syntax to easily pick up key commands that will help a developer produce their code or find bugs easier?

So, these Variables what do they do exactly?

Well there are many Local & Environmental Variables, they all contain stored values.

For instance the Variable ‘HISTFILE’ shows the location of the stored history file, ‘HISTSIZE’ shows the maximum lines of history commands & arguments the user has typed into the Shell and records this data in the ‘HISTFILE’ variable.

The first 2 commands below show the Environmental Variables that are set for the Shell: –

prompt> env

ORBIT_SOCKETDIR=/tmp/orbit-user

SSH_AGENT_PID=1257

TERM=xterm

SHELL=/bin/bash

XDG_SESSION_COOKIE=85250a19175ea63b09fa29dd4b72f884-1295208313.786947-1525384731

WINDOWID=62914563

GNOME_KEYRING_CONTROL=/tmp/keyring-kwfP0T

GTK_MODULES=canberra-gtk-module

USER=user

LS_COLORS=rs=0:di=01;34:ln=01;36:hl=44;37:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:

SSH_AUTH_SOCK=/tmp/keyring-kwfP0T/ssh

DEFAULTS_PATH=/usr/share/gconf/gnome.default.path

SESSION_MANAGER=local/user-desktop:@/tmp/.ICE-unix/1223,unix/user-desktop:/tmp/.ICE-unix/1223

USERNAME=user

XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg

DESKTOP_SESSION=gnome

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

PWD=/home/user

GDM_KEYBOARD_LAYOUT=gb

LANG=en_GB.utf8

GNOME_KEYRING_PID=1205

MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path

GDM_LANG=en_GB.utf8

GDMSESSION=gnome

SPEECHD_PORT=7560

SHLVL=1

HOME=/home/user

GNOME_DESKTOP_SESSION_ID=this-is-deprecated

LOGNAME=user

XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/

DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-pGwUxHIFic,guid=d14491e9ed074785b3d31a434d334f7a

LESSOPEN=| /usr/bin/lesspipe %s

DISPLAY=:0.0

LESSCLOSE=/usr/bin/lesspipe %s %s

XAUTHORITY=/var/run/gdm/auth-for-user-uKD5ZX/database

COLORTERM=gnome-terminal

_=/usr/bin/env

prompt> export

declare -x COLORTERM=”gnome-terminal”

declare -x DBUS_SESSION_BUS_ADDRESS=”unix:abstract=/tmp/dbus-pGwUxHIFic,guid=d14491e9ed074785b3d31a434d334f7a”

declare -x DEFAULTS_PATH=”/usr/share/gconf/gnome.default.path”

declare -x DESKTOP_SESSION=”gnome”

declare -x DISPLAY=”:0.0″

declare -x GDMSESSION=”gnome”

declare -x GDM_KEYBOARD_LAYOUT=”gb”

declare -x GDM_LANG=”en_GB.utf8″

declare -x GNOME_DESKTOP_SESSION_ID=”this-is-deprecated”

declare -x GNOME_KEYRING_CONTROL=”/tmp/keyring-kwfP0T”

declare -x GNOME_KEYRING_PID=”1205″

declare -x GTK_MODULES=”canberra-gtk-module”

declare -x HOME=”/home/user”

declare -x LANG=”en_GB.utf8″

declare -x LESSCLOSE=”/usr/bin/lesspipe %s %s”

declare -x LESSOPEN=”| /usr/bin/lesspipe %s”

declare -x LOGNAME=”user”

declare -x LS_COLORS=”rs=0:di=01;34:ln=01;36:hl=44;37:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:”

declare -x MANDATORY_PATH=”/usr/share/gconf/gnome.mandatory.path”

declare -x OLDPWD

declare -x ORBIT_SOCKETDIR=”/tmp/orbit-user”

declare -x PATH=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games”

declare -x PWD=”/home/user”

declare -x SESSION_MANAGER=”local/user-desktop:@/tmp/.ICE-unix/1223,unix/user-desktop:/tmp/.ICE-unix/1223″

declare -x SHELL=”/bin/bash”

declare -x SHLVL=”1″

declare -x TERM=”xterm”

declare -x USER=”user”

declare -x USERNAME=”user”

declare -x WINDOWID=”62914563″

declare -x XAUTHORITY=”/var/run/gdm/auth-for-user-uKD5ZX/database”

declare -x XDG_CONFIG_DIRS=”/etc/xdg/xdg-gnome:/etc/xdg”

declare -x XDG_DATA_DIRS=”/usr/share/gnome:/usr/local/share/:/usr/share/”

declare -x XDG_SESSION_COOKIE=”85250a19175ea63b09fa29dd4b72f884-1295208313.786947-1525384731″

user@user-desktop:~$

Whilst the command below shows a combination of Local & Environmental Variables that have been set for all Shell types: –

prompt> set

BASH=/bin/bash

BASHOPTS=checkwinsize:cmdhist:expand_aliases:extglob:extquote:force_fignore:histappend:interactive_comments:progcomp:promptvars:sourcepath

BASH_ALIASES=()

BASH_ARGC=()

BASH_ARGV=()

BASH_CMDS=()

BASH_COMPLETION=/etc/bash_completion

BASH_COMPLETION_COMPAT_DIR=/etc/bash_completion.d

BASH_COMPLETION_DIR=/etc/bash_completion.d

BASH_LINENO=()

BASH_SOURCE=()

BASH_VERSINFO=([0]=”4″ [1]=”1″ [2]=”5″ [3]=”1″ [4]=”release” [5]=”i486-pc-linux-gnu”)

BASH_VERSION=’4.1.5(1)-release’

COLORTERM=gnome-terminal

COLUMNS=207

DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-pGwUxHIFic,guid=d14491e9ed074785b3d31a434d334f7a

DEFAULTS_PATH=/usr/share/gconf/gnome.default.path

DESKTOP_SESSION=gnome

DIRSTACK=()

DISPLAY=:0.0

EUID=1000

GDMSESSION=gnome

GDM_KEYBOARD_LAYOUT=gb

GDM_LANG=en_GB.utf8

GNOME_DESKTOP_SESSION_ID=this-is-deprecated

GNOME_KEYRING_CONTROL=/tmp/keyring-kwfP0T

GNOME_KEYRING_PID=1205

GROUPS=()

GTK_MODULES=canberra-gtk-module

HISTCONTROL=ignoreboth

HISTFILE=/home/user/.bash_history

HISTFILESIZE=500

HISTSIZE=500

HOME=/home/user

HOSTNAME=user-desktop

HOSTTYPE=i486

IFS=$’ \t\n’

LANG=en_GB.utf8

LESSCLOSE=’/usr/bin/lesspipe %s %s’

LESSOPEN=’| /usr/bin/lesspipe %s’

LINES=54

LOGNAME=user

LS_COLORS=’rs=0:di=01;34:ln=01;36:hl=44;37:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.

taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31

:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*

.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.

rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=0

0;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:’

MACHTYPE=i486-pc-linux-gnu

MAILCHECK=60

MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path

OPTERR=1

OPTIND=1

Lets say we wanted to change the ‘HISTSIZE’ to only display the last 100 commands that we use in the Shell when we cycle through them using the up arrow on the keyboard. To limit the ‘HISTSIZE’ to only the last 100 entries we would do so like this: –

prompt> HISTSIZE=100 ### Limiting the HISTSIZE to 100

prompt> echo $HISTSIZE ### seeing what value the HISTSIZE now has

100 ### The HISTSIZE is now 100 as you can see!

The above example was setting a Local Variable to the Shell we are working on only. Lets say that we wanted this Variable to be used for all other Shells and to keep the same value too? Then we would set the Environmental Variable to 100 and it will be shared across all Shells that will be used on the system! See example below: –

prompt>exportHISTSIZE=100

prompt>echo $HISTSIZE ### Now if we were to use another Shell like C shell and then type this command to see what the value of HISTSIZE is then we would get the same value as below

100

There are many variables that you can edit the value of, some are more useful than others. For example lets say that you want to change the prompt to show where you are on every command line, then you would edit the ‘PS1’ variable like so: –

prompt>PS1=”<\$PWD>” ### To set this as an eniromental variable you can use the work export before the variable just like in the previous example

</home/user> ### The prompt now displays the present working directory on each command line

You can also alter the value of ‘PS1’ so that it shows the user logged in, hostname, ip address, etc on each command line once you are happy with your variable value altering skills

Summary

Will definitely be altering the values of certain variables for a more customized shell that will help me as a user have more beneficial information. There are many other variable values that can be set that include but not limited to: –

HOME, MAIL, PATH, PS2, SHELL, TERM, DISPLAY, etc. maybe a quick google will find more variables that can be altered?

Advertisements

From → Linux

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: