Professional Documents
Culture Documents
echo "4.exit"
read ch
case "$ch" in
read fname
if [ -f $fname ]; then
read nwname
mv $fname $nwname
else
fi
;;
who;;
4)exit;;
esac
OUTPUT:
admin@DESKTOP-IO0TGBV ~/BCA
$ sh exp1st.sh
OPTION ARE
4.exit
w.sh
l.sh
admin@DESKTOP-IO0TGBV ~/BCA
$ sh exp1st.sh
OPTION ARE
1.Rename the file
4.exit
/home/admin/BCA
admin@DESKTOP-IO0TGBV ~/BCA
$ sh exp1st.sh
OPTION ARE
4.exit
admin@DESKTOP-IO0TGBV ~/BCA
$ sh exp1st.sh
OPTION ARE
4.exit
4
NAME : PREETHI DATE:2/1/2022
PROGRAM: Write a shell script to accept many files name through command
line. Do the following for each file name.
a)If it an ordinary file, display the content and check it has execute permission
for arg in $*
do
if [ -f $arg ];then
echo "________________"
cat $arg
if [ -x $arg ];then
else
fi
echo"__________________"
ls -l $arg
else
echo"_____________"
done
OUTPUT:
---------
SHC.sh is a file
file is executable
---------
SHC2.sh is a file
-------
total 0
---------
College.sh is a file
file is executable
---------
a) Append the content of a file to another file(Display the message if the file
doesn’t exist in the directories)
b) List all the file names/directories names in the present working directory
which has the specified pattern.
c)Assign the execute permission to a specified file for the owner and group.
while [ : ]
do
echo "4.exit"
read ch
case $ch in
read sname
if [ -f $sname ];then
read dname
if [ -f $dname ];then
cat $sname>>$dname
cat $dname
else
fi
else
fi
;;
read pattern
ls $pattern;;
read fname
ls -l $fname
chmod ug + X $fname
ls -l $fname
;;
4)exit;;
esac
done
OUTPUT:
lab1@lab1-PC ~/BCA
$ sh prm3.sh
1.appending a file
2.list file or directory with specified pattern
4.exit
shc.sh
a.sh
1.appending a file
4.exit
ex*
1.appending a file
4.exit
enter a filename
a.sh
1.appending a file
4.exit
PROGRAM: Write a shell script access many characters and count individuals
vowels, digits, spaces, special characters, and constants.
read str
echo $n
VC=0
dc=0
sp=0
sc=0
cc=0
i=1
case $ch in
;;
;;
;;
;;
*) sc =` expr $sc + 1`
esac
i=`expr $i + 1`
done
OUTPUT:
$ sh exp4.sh
Enter a string:
sacred heart12345@#
19
number of vowels: 4
number of digits: 5
number of spaces: 1
number of consonant: 7
NAME : PREETHI DATE:12/1/2022
PROGRAM: Write a shell script to accept your options for deleting(-d) or for
copying(-c) a file and filename(s) through command line arguments.
a) Check whether the given arguments are sufficient for the selected option.
c) while copying,if the destination file already exists prompt for overwriting.
echo case $1 in
-d) if [ $# -ne 2 ]
then
echo ********output*********
echo ************
exit
fi
file=$2
if [ ! -f $file ]
then
echo **********output************
exit
fi
rm $file
echo *********************output************
;;
-c) if [ $# -ne 3 ]
then
echo *********output************
echo **********
exit
fi
file=$2
if [ ! -f $file ]
then
echo ********output***********
echo *****************
exit
fi
option=y
file2=$3
if [ -f $file2 ]
then
echo **********output****************
read option
fi
case $option in
;;
;;
esac
;;
;;
Esac
OUTPUT:
$ sh pg4.sh -d
********OUTPUT********
$ sh pg4.sh -d A.sh
******OUTPUT*********
$ sh pg4.sh B.sh
invalid options
SHC.sh college.sh exp1.sh exp2.sh pgm3.sh exp4.sh exp5.sh
$ shpg4.sh -d X.sh
*******OUTPUT********
******OUTPUT*******
******OUTPUT*******
******OUTPUT*******