Posts Tagged ‘command line’

Who provides a Command Line Interface to the OS?  It’s actually the shell, the program that manages the interaction between the system and the user. the shell can be accessed via virtual console, terminal attached to a serial line, remote access over tcp/ip, X terminal running on an X session. There are various type of shell. Some of them are the following:
– sh or Bourne Shell: original shell used in UNIX system
– bash or Bourne Again Shell: Standard GNU Shell
– csh or CShell:  resembles of C PL. Asked by programmers
– tcsh or Turbo C Shell: superset of CShell
– ksh or Kor Shell:  a superset of sh, for people w/ UNIX background.

Okay, now that you are introduced to shells. It’s time for some practice on command lines. I’ve listed some shell-related commands with their function. Try them out! 🙂

cat etc/shells: list known shells of Linux system
echo $SHELL: check SHELL you are using.
chsh: change the shell. It modifies etc/passwd
chsh -s shell: change to a new shell

Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer[Wikipedia]. Environment variables in Linux are set in .bashrc.

set PS1
PS1= format
export PS1=
echo $PS1
unset PS1
x=5
echo $x

echo command is used to view the content of the specified variable.
set PS1: set a value for the variable PS1
P1=value: assign the new value
export PS1 make the variable environmental
unset PS1: unset the value of PS1
x=5: assign value to x
$SHELL - environment variable
$x - user defined variable

All environment variable are in all-caps. To see all defined variables, use the env command. Use | grep to search a specific variable

env | grep SHELL

Bash prompts are of two types. The primary and the secondary.
The primary bash prompt is set by the environment variable PS1. The secondary prompt is set by variable PS2.

The bash prompt settings:
$ export PS1=[\u@\h \w]\$
[dhee@engrPC ~]$
–   \u username
–   \h host name
–   \$ $ for users and # for root
–   \w full path of current working directory, ~ for home directory
–   \W base name of the current working directory
–   \! history number of the current command

The PATH  lists directories the shell searches, for the commands the user may type without having to provide the full path. To add a directory to path, type PATH=”$PATH:directory or PATH=”directory:$PATH”. This modifies the environment file in the etc directory.You can also modify /etc/login.defs to change the PATH of super users.