Linux Shell Programming 1

My notes on reading Linux Shell Scripting Tutorial

Print a variable

$ echo $HOME

Define User defined variable

$ n=10
$ vech=
$ vech=""

Shell Arithmetic

$ expr 1 + 3
$ echo `expr 6 \* 3`


$ echo "$HOME"

$ echo '$HOME'

$ echo "Today is `date`"
Today is Tue Oct 12 13:50:47 CST 2010

$ echo 'Today is `date`'
Today is `date`

Exit Status

$ rm unknown1file
rm: cannot remove `unkown1file': No such file or directory
$ echo $?

$ ls
$ echo $?

The read Statement

$ vim sayH
echo "Your name please:"
read name
echo "Hello $name, Lets be friend!"

$ chmod 755 sayH
$ ./sayH
Your name please:mitnk
Hello mitnk, Lets be friend!

Wild cards

? * [abc] [a-c] [!a-c] [^a-c]
[[:digit:]] alnum, alpha, ascii, blank, cntrl, digit, graph, lower, print, punct, space, upper, word, xdigit

More command on one command line


Command arguments

$ vi demo
# Script that demos, command line args
echo "Total number of command line argument are $#"
echo "$0 is script name"
echo "$1 is first argument"
echo "$2 is second argument"
echo "All of them are :- $* or $@"

Redirection of Standard output / input

$ ls > myfile
$ date >> myfile

$ cat < myfile
$ cat > myfile
(Ctrl + C to exit)


ls | wc -l

Process defined as: "A process is program (command given by user) to perform specific Job. In Linux when you start process, it gives a number to process (called PID or process-id), PID starts from 0 to 65535."

Linux Command Related with Process ps - To see currently running process kill {PID} - To stop process by PID killall {Process-name} - To stop processes by name

ps -ag - To get information about all running progress linux-command & - Run background

ps ax | grep process-U-want-to-see pstree