Shell/command interpreter ● interactive user interface with an operating system ● command line interface (CLI) ● understands and executes the commands a user enters ● outer layer of an operating system (in contrast to the kernel) ● invokes another program, shows the system settings, allows file system modification etc. ● many shells available on a typical Linux/Unix/MacOs systems: sh, bash, zsh, ksh
Shell / command interpreter. interactive user interface with an operating system command line interface (CLI) understands and executes the commands a user enters outer layer of an operating system (in contrast to the kernel) - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Shell/command interpreter
● interactive user interface with an operating system● command line interface (CLI)● understands and executes the commands a user
enters● outer layer of an operating system (in contrast to
the kernel)● invokes another program, shows the system
settings, allows file system modification etc.● many shells available on a typical
Linux/Unix/MacOs systems: sh, bash, zsh, ksh
BASH
● Bourne Again SHell - enhanced version of the original Bourne shell program, sh (written by Steve Bourne)
● on local system: -started after a successful login (if specified in/etc/passwd) -terminal emulators (xterm, gnome-terminal, konsole, ... - depends on window manager)
● on remote system : -ssh user@remotehost (Unix, Linux, MacOS,...) -ssh client program e.g. PuTTY (Windows)
HOME - current user's home directory IFS - list of characters that separate fields PATH - colon-separated list of directories in which the shell looks for commandsPS1 the primary prompt stringUID - numeric real user ID of the current userRANDOM generates random integer between 0 and 32767 PWD the current working directory OSTYPE - string describing the operating system HOSTNAME - name of the current hostBASH - full pathname used to execute the current instance of Bash and many more ...
Pipe examples
● ls -al|grep ^-|tr -s " " " "|cut -f5,9 -d" "|sort -n(show only regular files in the current directory with their size, sorted by size)
● ls -alt|tr -s " " " "|cut -d" " -f9|head -n2|tail -n1(write name of the last modified file )
● echo $USER `finger 2>/dev/null|grep $USER|wc -l`(write number of user sessions)
● cat /etc/passwd|sort -t":" -k3 -n|cut -d":" -f1,3 (show users logins with their uid, sorted by uid)
● cat *.java|sort|uniq|wc -l (write number of different lines in all *.java files)
● [ -f file.txt ] true if file exists and is a regular file
● [ -d file.txt ] true if file exists and is a directory
● [ -e file.txt ] true if file exists (regardless of type)
● [ -z string ] true if the length of string is zero
● [ s1 = s2 ] true if the strings s1 and s2 are identical
● [ s1 != s2 ] true if the strings s1 and s2 are not identical.
● [ s1 < s2 ] true if string s1 comes before s2 based on the ASCII value of their characters
●
test
● [ n1 -eq n2 ] true if the integers n1 and n2 are algebraically equal
● [ n1 -ne n2 ] true if the integers n1 and n2 are not algebraically equal
● [ n1 -ge n2 ] true if the integer n1 is algebraically greater than or equal to the integer n2
● [ n1 -lt n2 ] true if the integer n1 is algebraically less than the integer n2
● [ ! expression ] true if expression is false
● [ expression1 -a expression2 ] true if both expression1 and expression2 are true.
● [ expression1 -o expression2 ] true if either expression1 or expression2 are true.
no_backup=0;
if test -e backup
then
echo removing directory backup
rm -r backup 2>/dev/null
no_backup=$?
fi
if test $no_backup -eq 0 ; then
echo creating directory backup
mkdir backup
echo copying files
cp -v *.ini *.conf backup >summary.txt
cat summary.txt
echo Files copied:
cat summary.txt| wc -l
else
echo Directory \"backup\" can\'t be removed
fi
Special parameters $? expands to the exit status of the most recently executed foreground command
$@ expands to the positional parameters. when the expansion occurs within double quotes, each parameter expands to a separate word (similar to $*, but $* is no longer recommended)
$# expands to the number of positional parameters in decimal.
$$ Expands to the process ID of the shell.
$0 Expands to the name of the shell or shell script.