Featured Post

Thursday, March 24, 2016

Shell program to add two numbers and to display the result on the screen


open the vi editor with file name for example

vi add.sh   and press enter you go to editor

/* add.sh */


echo "enter any two numbers"
read a
read b
c=`expr $a + $b`
echo $c



now go to command mode and check whether add.sh program have execute permissions are not by typing ls -l command at terminal window.

if dont have execute permissions give execute permission using chmod command

/home/anil/~$ chmod 777 add.sh

 am giving read write execute permissions for owner group and others using chmod with 777 octal permission.

now execute
/home/anil/~$ sh add.sh
enter any two numebrs
12
23
25


echo is like printf statement in c programming. its an output statement.
bash shell programming is type less programming .

to read a value from keyboard simply use read function
read a
to display a value in a variable use $ symbol before variable
echo $a

please note that whenever you are using arithmetic operators one must use expr combination with grave ascent symbol(`) . for grave ascent symbol press shift + tilde character near one letter key)

note: every shell must have a name with extension .sh.
to execute shell program we use sh command like
sh filename
sh add.sh





Unix operating system Linux operating system shell programming bourn shell kourne shell c shell difference between unix and linux operating system , history of UNIX, red hat operating system. UNIX OS architecture , kernel utility programs , file handling process handling inter process communication pipes shared memory message queues socket programming TCP/IP , UDP programming , One to One chat Application , Basic shell program to add two numbers , echo function , while loops clear gt lt le ge ne eq if fi while do done case array in unix strings , cut copy paste cat dir pwd getcwd chdir command read write stat lseek fstat flock mechanism.even or add program vi editor command ni vi editor command mode esc mode insert mode aa dd x :q :wq :w

No comments:

Post a Comment