echo -e "With no quotes :$all\n"
echo -e "With single quotes :'$all'\n"
echo -e "with double quotes :\"$all\"\n"
With no quotes :Hi!
With single quotes :'Hi!'
with double quotes :"Hi!"
Write a shell script that has two user created variables, var1 and var2.Ask for
values of the variable from the user and take in any values of the two variables and
then print them as:-
i)values of var1 followed by values of var2 separated by a comma
ii) values of var2 followed by values of var1 separated by the word \u201cand\u201d.
echo -e "Enter variable 1 :\c"
if [ -z var1 ] ; then
echo -e "You did not entered variable. Exit\n" ; exit 1
echo -e "Enter variable 2 :\c"
if [ -z var2 ] ; then
echo -e "You did not entered variable. Exit\n" ; exit 2
echo -e "i) $var1 , $var2 "
echo -e "ii)$var2 and $var1 "
[root@localhost ~]# ./prob2.sh
Enter variable 1 :var1
Enter variable 2 :var2
i) var1 , var2
Write a shell script that reads command line arguments and prints the number of
arguments. Given this sequence of words as command line arguments \u201cTo the OS
Laboratory at Alpha Lab Welcome\u201d, the script should echo back the information that
there are 8 arguments. Additionally it should echo back some of the arguments in the
\u201cWelcome To the alpha Lab Os Laboratory\u201d.
echo -e "Number of arguments :$#"
echo -e "$8 $1 $2 $6 $7 $3 $4"
[root@localhost ~]# ./prob3.sh To the OS Laboratory at Alpha Lab Welcome
Write a shell script that accepts a filename as an argument and performs the following
tasks for that file:
a. searches all possible directories and prints the pathname if the file exists otherwise
prints an error message and exits.
b. prints the access rights of the file.
c. prints the size of the file.
d. prints the date of creation and the last date of modification of the file.
echo -e "This program takes only one argument" ; exit 1
if [ -z "$1" ] ; then
echo -e "Filename Null. Exit\n" ; exit 2
echo -e "Searching all possible directories....\n"
find . -name "$1" 2>/dev/null >temp
if [ `cat temp | wc -l ` -eq 0 ] ; then
echo -e "No such file exists.\n" ; exit 3
echo -e "
for var in `cat temp` ; do
aright=`ls -l $var | tr -s ' ' |cut -d" " -f1`
size=`ls -l $var | tr -s ' ' |cut -d" " -f5`
mdate=`ls -l $var | tr -s ' ' |cut -d" " -f6,7`
printf "%19s %13s %6d %16s\n" $var $aright $size "$mdate"
Problem 5:- Write a shell script that accepts a file name as input .The program then
asks for a string of characters(i.e. any word ) from the user .The file will be
searched to find whether it contains the given word .If it does, the program will
display the no. of occurrences of the word. The program should also display the line
numbers where the word occurred .If the file does not contain the word, and then an
appropriate error message will be displayed.
echo Enter a File Name
if [ -f $fname ]
echo Enter a Pattern to be Recognized
if ! grep $pattern -n $fname
[root@localhost ~]# cat soumya
[root@localhost ~]# ./prob5.sh
Enter a File Name
Enter a Pattern to be Recognized
This action might not be possible to undo. Are you sure you want to continue?