0% found this document useful (0 votes)
10 views

prgrams

Uploaded by

tayix49837
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

prgrams

Uploaded by

tayix49837
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

2.

program

echo "Enter the Number: " read n


s=0 rev="" temp=$n

while [ $n -gt 0 ];
do
s=$(( $n % 10 ));
rev=$( echo ${rev}${s} ) n=$(( $n / 10 ));
done

if [ $temp -eq $rev ]


then
echo "Number is Palidrum"
else
echo "Number is not Palidrum"
fi

output:-
Enter the Number: read n
main.bash: line 4: [: -gt: unary operator expected
Number is Palidrum

-----------------------

3.program

a=45 b=41 c=34

if [ $a -gt $b -a $a -gt $c ]; then echo "A is Greater"


elif [ $b -gt $c ]; then echo "B is Greater"
else
echo "C is Greater"
fi

output:-
A is Greater

-----------------------

4.program

a=$(date +"%H")
if [ $a -le 12 ]
then
echo "Good Morning"
elif [ $a -le 17 ]
then
echo "Good Afternoon"
elif [ $a -le 20 ]
then
echo "Good Evening"
else
echo "Good Night"
fi

output:-

Good Afternoon
-----------------------

5.program

while read line; do


echo "$line"
cp hello file
done < hello

------------------------

6program

secure_input() {
read -s "$1"
echo
}

check_credenials() {
local username="$1"
local password="$2"
local valid_username="username"
local valid_password="password"

if [ "username" -eq "valid_username" && "password" -eq "valid_password" ]


then
echo "welcome,$username"
else
echo "Invalid username"
fi
}

echo "please enter username" read $username


echo "Please enter password" read secure_input $password

check_credenials " $username $password "

output:-

please enter username read


Please enter password read secure_input
main.sh: line 12: [: missing `]'
Invalid username

------------------------

7program

file=""
echo -n " Enter file name " read file
if [ ! -f $file ]
then
echo "$file not exits" exit 1
fi
sort -n $file

output:-
Enter file name read file

----------------------------------

8.program

sum=0 a=1
while [ $a -ne 0 ]
do
echo " Enter the value of a " read a
sum=` expr $sum + $a`
done
echo "Total:= $sum"

output:-

Enter the value of a 5


Enter the value of a 5
10

-----------------------------

9.program

if [ -z "$1" ]; then
echo "Error: Please provide a number as input."
echo "Usage: ./reverse_number.sh <number>"
exit 1
fi

input=$1
reverse=""

while [ -n "$input" ]; do
reverse="${input:0:1}$reverse"
input="${input:1}"
done

echo "Reversed number: $reverse"

output:-
./reverse_number.sh 1234
Reversed number: 4321

---------------------------------

10.program

echo "Enter first file name" read f1


echo "Enter second file name" read f2
echo "Enter third file name that u want to copy contact" read n
p=`cmp $f1 $f2`
if [ $? -eq 0 ]
then
`cp $f1 $n`
echo"File copy successfully"
else
echo "File is notb same"
fi

output:-

Enter first file name read f1


Enter second file name read f2
Enter third file name that u want to copy contact read n

-------------------------------

11.program

for i in `find /project/zerofile -type f -size 0c` do


echo "$i has 0-size"
`rm $i`
done

output:-

2 has zero size

----------------------------------

12.program

echo "Enter Directory for sorting" read n


p=`ls -lhS`
echo "files: $p "
echo "Sort Sccessfully"

output:-
Enter Directory for sorting project/another
Sort Successfully

-----------------------------------

13.program

echo "Enter D to display the current directory"


echo "Enter L to list the directory"
echo "Enter M to make directory"
echo "Enter C to change the directory"
echo "Enter P to copy the file"
echo "Enter R to rename the file"
echo "Enter T to Delete the file"
echo "Enter E to Edit the file"
read a
case "$a" in
'D')
pwd
;;
'L')
ls
;;
'M')
echo "Enter Directory name"
read b
mkdir "$b"
;;
'C')
cd
;;
'P')
echo "Enter Old file name"
read o
echo "Enter new file name"
read n
cp "$o" "$n"
;;
'R')
echo "Enter file name that u want to rename"
read p
echo "Enter newfile name"
read q
mv "$p" "$q"
;;
'T')
echo "Enter file name that u want to remove"
read r
rm "$r"
;;
'E')
echo "Enter file name to edit"
read e
esac

output:-

Enter D to display the current directory

Enter L to list the directory

Enter M to make directory

Enter C to change the directory

Enter P to copy the file

Enter R to rename the file

Enter T to Delete the file

Enter E to Edit the file

--------------------------------

14.program

p=10
if [ $p -eq 0 ]
then
echo "Argument not pass"
else
centi=$(("$p * 100"))
echo "$p meter is equals to $centi centimeter"
fi
output:-
Argument not pass

-------------------------------

15.program

for file in * do
if [ -f $file ]
then
if [ -r $file ]
then
ls -l $file
fi
fi
done

output:-

-------------------------------

16.program

output:-

You might also like