06 OS06 Shell Scripting LAB
06 OS06 Shell Scripting LAB
06 OS06 Shell Scripting LAB
1. What is a Shell?
A shell is a command-line interface (CLI) that provides a way for users to interact with the operating
system.
Shell is a program that takes your commands (text-based) and sends them to the operating system
to execute.
Examples of shells include Bourne Shell (sh), Bash (Bourne-Again Shell), rbash, dash
Cat /etc/shells
Write the output
which bash
Write the output
4. On the command line interface, what is the current working directory of your system?
pwd
Write the output
5. Navigate to the current user directory and create a new directory called ‘ostasks’ and change the
directory to ostasks
cd /home/{user name}
mkdir ostasks
cd ostasks
Page 1 of 6
6. Create a new file with .sh extension named ‘firstprogram’
8. Edit the same file and write a command that first saves the current date and time of the system and
then displays it.
#!/bin/bash
echo “hello”
current_datetime=$(date)
echo “Current Date and Time: $current_datetime”
9. To write a comment in a shell script use ‘#” hash symbol before the comment
# this is a comment
temp=10
echo “the value of temp = $temp”
#! /bin/bash
Page 2 of 6
# how to read from the same line
13. Arrays
if [ condition ]
then
statement
fi
Page 3 of 6
# comparing the two strings
word=”school”
if [ “$word” = “school”]
then
echo “condition is true”
fi
Page 4 of 6
if [ condition ] || [ condition ] # logical OR
then
statement
fi
n=1
while [ $n –le 10 ] OR (( $n <= 10 ))
do
echo “$n”
n=$(( n+1 ))OR (( n++ ))
done
Page 5 of 6
Task 1: Run the following command and explain its purpose. 'lshw'. If the command doesn't work, try to find
the solution.
Task 2: Write a bash script that finds the first 500 prime numbers.
Task 3: Write a bash script that displays the number of cores of your machine.
Task 4: By default, on your system, all cores are online. Online core means that the core is active. Find the
Task 5: The system's cores are numbered from 0 to n. Find which is the default core of your system.
Task 6: Write a bash script using a for loop that disables or offline all the cores except the default core.
Task 7: Write a bash script using a for loop that enables or online all the cores except the default core.
Task 8: Write a bash script that reads the names of five files and creates five text files in the current working
directory.
Task 9: Write a bash script that deletes the files (created in task 7).
Task 10: Write a bash script that reads the integer input' n' from the keyboard. It displays the current date
Task 11: Write a bash script that reads the two strings from the keyboard and compares them for equality.
Page 6 of 6