Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
5Activity
0 of .
Results for:
No results containing your search query
P. 1
Unix Programs 2

Unix Programs 2

Ratings: (0)|Views: 960|Likes:
Published by Nagender Andugula

More info:

Published by: Nagender Andugula on Aug 13, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

11/16/2014

pdf

text

original

 
http:/ / enhanceedu.iiit.ac.in/ ttp/ index.php/ User:vapremaim s Page 1
1) Write a non recursive shell script which accepts any number of arguments and printsthem in the reverse order (for example, if the script is named rags, then executing ragsABC should produce CBA on the standard output
a=$#echo "Number of arguments are" $ax=$*c=$ares=''while [ 1 -le $c ]doc=`expr $c - 1`shift $cres=$res' '$1set $xdoneecho Arguments in reverse order $res
Output
sh 1prg.sh a b cNo of arguments arguments are 3Arguments in reverse order c b a
Descriptionwhile
The syntax of 
while
loop construct iswhile [ expr ]docommandlistdoneThe
commandlist 
will be executed until the
expr 
evaluates to false.
$*
stands for list of all the arguments,
$#
for the number of arguments
Setset
is the mechanism of placing values in positional parameters. The
set
command withno parameters will print out a list of all the shell varibles
Shiftshift
1 reduces the parameter number by one (
$2
becomes
$1
).
$1
vanishes with every
shift
operation.
 
http:/ / enhanceedu.iiit.ac.in/ ttp/ index.php/ User:vapremaim s Page 2
2) Write a shell script that accepts two file names as arguments, checks if the permissionsfor these files are identical and if the permissions are identical, output commonpermissions and otherwise output each file name followed by its permissions.
if [ $# -ne 2 ]thenecho "pass 2 argument"exitfiecho enter file nameread f1echo enter the second file nameread f2p1=`ls -l $f1 | cut -c 2-10`p2=`ls -l $f2 | cut -c 2-10`if [ $p1 = $p2 ]thenecho permissions are sameecho $p1elseecho permissions are differentecho permission of file $f1 is $p1echo permission of file $f2 is $p2fi
Output:
enter file name10a.shenter the second file name2a.shpermissions are samerw-r--r—enter file name1enter the second file name10a.shpermissions are differentpermission of file 1 is rwxrwxrwxpermission of file 2 is rw-r--r—
 
http:/ / enhanceedu.iiit.ac.in/ ttp/ index.php/ User:vapremaim s Page 3
Descriptionif-then-else
The syntax of the if-then-else construct isif [ expr ] thensimple-commandfiorif [ expr ] thencommandlist-1elsecommandlist-2if The expression
expr 
will be evaluated and according to its value, the
commandlist-1
or the
commandlist-2
will be executed.

Activity (5)

You've already reviewed this. Edit your review.
ms.abeer liked this
1 thousand reads
1 hundred reads
Brian Ng liked this
srikanthkg liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->