0% found this document useful (0 votes)
0 views4 pages

LINUX If Else

The document contains three shell scripts: the first calculates gross salary based on input and assigns a job title, the second provides user options for displaying user count, current directory, or file details, and the third checks for a file's existence, creating it if necessary, and displays its line and word counts. Each script includes user prompts and conditional logic to handle various scenarios. The scripts demonstrate basic shell scripting techniques for user interaction and file management.

Uploaded by

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

LINUX If Else

The document contains three shell scripts: the first calculates gross salary based on input and assigns a job title, the second provides user options for displaying user count, current directory, or file details, and the third checks for a file's existence, creating it if necessary, and displays its line and word counts. Each script includes user prompts and conditional logic to handle various scenarios. The scripts demonstrate basic shell scripting techniques for user interaction and file management.

Uploaded by

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

1.

Write a shell script to accept empno,enm,HRA,TA,Basic sal for


employee and show gross sal.
if gross sal >1L -> sr.manager
gross sal >80000 and < 1L -> Mgr
gross sal >50000 and < 80000 -> Exc.Mgr

store said jobs add this in new file.

empno | enm | sal | job


1 | A | 800000| Mgr

echo "Enter emp no: "

read emp_no

echo "Enter emp name: "

read emp_name

echo "Enter HRA: "

read hra

echo "Enter TA: "

read ta

echo "Enter basic salary"

read b_sal

gross_sal= $($hra + $ta + $b_sal)

if [ $gross_sal -ge 100000 ]

then

echo "Assign as Senior manager"

srm="Senior manager"

echo $emp_no"|"$emp_name"|" $gross_sal"|" $srm >> cat > info

elif [ $gross_sal -ge 80000 ] -a [ $gross_sal -lt 100000 ]

then

echo "Assign as Manager"

m= "Manager"
echo $emp_no"|"$emp_name"|" $gross_sal"|" $m >> cat > info

elif [ $gross_sal - ge 50000 ] -a [ $gross_sal -lt 80000 ]

then

echo "Executive Manager"

exm= "Executive Manager"

echo $emp_no"|"$emp_name"|" $gross_sal"|" $exm >> cat > info

else

echo "Error"

fi
Q2. Write a shell script to write down conditions accept option from
user.
1. show no of user.
2. showing current working dir.
3. file details in long list.

echo -e "\t Enter opt"

read opt

case $opt in

1) who;;

2) pwd;;

3) ls -l;;

*0) echo "Option is invalid"

esac
Q3 Write a shell script to accept a filenm. if does not exists. create
it show the no of lines andwords of the file save in variable display
its content.

echo "Enter the file name: "

read a

if test -e $a

then

echo "The file already exists"

cat $a

echo "Total lines count: "

wc -l $a

echo "Total word count : "

wc -w $a

else

echo "Enter contents to be added in the file"

read c

cat > $c

cat $c

echo "Total lines count: "

wc -l $c
echo "Total word count : "

wc -w $c

fi

You might also like