Professional Documents
Culture Documents
GROUP: C1
1. Write a shell script that print the sum of three numbers which collects
arguments from command line and hold these arguments in positional
variable. The program must print how many arguments has been
collected and print these values
CODE:
fo()
echo "the total arguments are:- $#
ech
OUTPUT:-
}
"
"
"
"
2. Write a shell script that nd the average of numbers that takes input
from command line arguments
CODE:
OUTPUT:-
3. Write a shell script that run the following command “ls -l” and “cat /
home/a.txt” and print there respective exit status.
c
"
fi
"
4. Write a shell script that run the following command “who | grep user” (made of
two separate commands who and grep) and print the exit status of above combined
command . You need to identify this exit status for which command.
5. Write a shell script that takes input “ls” “-l” (seperately) from command line. Print
the following
CODE:
le="$1
if [-w $ le ] && [ -r $ le ] then chmod 777 $ le && echo "File Permission has
been changed
fi
fi
fi
fi
fi
-
"
fi
"
fi
"
fi
t
fi
7. Write a shell script to take a string as input and print the output of
following operatio
e.g. String=ABCDEEW1231sdfsadfas23
1. echo ${string:5
2. echo ${string:7:0
3. echo ${string:7:-2
4. echo ${string: -7:-2
CODE:
echo "Enter the string:-
read strin
echo ${string:5
echo ${string:7:0
echo ${string:7:-2
echo ${string:-7:-2
OUTPUT:
8. Write a shell script that take input a string of 10 character (e.g. array=(a b c d A 4 5
3 2 w)) from command line. Print the value of ${array[@]:7}. And this can be done
shift operation. Extend the program using shift operation for same output
CODE:
"
"
"
while [ $i -lt $n
d
read a[$i
i=`expr $i + 1
don
echo ${a[@]:7
echo "print the same output with shift operation:-
set -- "${a[@]:7}
while (( $# )
d
echo "$1
shif
don
OUTPUT:-
o
"
"
"
CODE:
sum=
for i in $@
do sum=$((sum+i))
echo $sum
don
echo $su
exit
0
fi
fi
.