Professional Documents
Culture Documents
Kalyani Government Engineering College: Cse, 3 Year, 6 Sem Sub: Operating System Lab I
Kalyani Government Engineering College: Cse, 3 Year, 6 Sem Sub: Operating System Lab I
Submitted by:
$mkdir KGEC
$cd KGEC
$mkdir CSE IT ECE ME EE
$cd CSE
$mkdir First_Year Second_Year Third_Year Fourth_Year
#!/bin/bash
echo $(date), $USER, $PWD
Output -
$Sun Apr 7 22:24:22 IST 2019, Shuva, /home/Shuva
#!/bin/bash
echo $SHELL
Output -
$/bin/bash
4 . Shell script to display users along with column headings -
#!/bin/bash
echo "Currently logged on users:"
who
5. Shell script that will take some command line arguments and displays the name of the
shell script file, total number of arguments and the value of those arguments.
#!/bin/bash
for ((i=1;i<=$#;i++));
do echo "Argument $i is ${!i}";
done
O/P :
$ bash myscript.sh a b
Name of the fle is myscript.sh
Total Number of arguments is 2
Argument 1 is a
Argument 2 is b
6. Write a Shell script that will take a name as command line arguments and display the
same.
#!/bin/bash
O/P :
$bash Anirban
Hello Anirban!, welcome to UNIX!
7. Write a simple shell script myscript.sh that takes a path of a directory as a command
line argument and list all files and folders inside the given directory.
#!bin/bash
8. Write a Shell script that will take two numbers as command line arguments and
displays their sum, difference, product and division.
#!/bin/bash
O/P
$bash nums.sh 4 2
sum is 6
product is 8
quotient is 2
#!bin/bash
echo $$
O/P : 4567
10. Write a Shell script that will display the exit status of the last program
Ans :
echo $?
O/P : 0
11. Write a Shell script that will display the current username.
echo $USER
O/P : Shuva
12. Take username as an argument and show whether it’s logged in or not .
#!/bin/bash
O/P :
$bash check.sh adam
User adam is not logged in
#!/bin/bash
case "$2" in
"+")
echo Result $(($1 + $3))
;;
"*")
echo Result $(($1 * $3))
;;
"/")
echo Result $(($1 / $3))
;;
"-")
echo Result $(($1 - $3))
;;
*)
echo "Unknown operation"
;;
esac
O/P
$bash switchcase1.sh 6 / 2
Result 3
$bash switchcase1.sh 4 # 2
Unknown Operation
#!/bin/bash
case "$1" in
"1")
echo "Day is Monday"
;;
"2")
echo "Day is Tuesday"
;;
"3")
echo "Day is Wednesday"
;;
"4")
echo "Day is Thursday"
;;
"5")
echo "Day is Friday"
;;
"6")
echo "Day is Saturday"
;;
"7")
echo "Day is Sunday"
;;
*)
echo "Not a day of the week"
;;
esac
O/P :
$bash switchcase2.sh 3
Day is Wednesday