0% found this document useful (0 votes)
3 views2 pages

Essential Bash Scripting Tasks

Uploaded by

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

Essential Bash Scripting Tasks

Uploaded by

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

Subject: Bash Scripting

Read all the questions first then start answering:


1) Write a script that greets the user by name.
The script should:

• Ask the user for their name


• Print: Hello, <name>!

2) Write a script that checks if a directory exists.


The script should:

• Ask the user for a directory name


echo "Enter directory name:"

read dirname

• Print Directory exists if it exists, otherwise Directory does not exist

3) Write a script that checks if a file exists and is readable.


The script should:

• Ask for a filename


• If the file exists and is readable, print File is readable

• Otherwise print File is not readable or does not exist

4) Write a script that determines if a number is even or odd.


The script should:

• Ask the user for a number

• Print Even or Odd

5) Write a script that prints the numbers from 1 to 10 using a for loop.

6) Write a script that counts how many .txt files are in the current directory.
The script should:
• Count .txt files

• Print: There are X .txt files


7) Write a script that displays a simple menu.
The script should:

• Show:
1) Show current directory
2) Show date

• Read the user’s choice

• Run pwd for 1, date for 2, otherwise print Invalid choice

8) Write a script that asks for a password and checks if it matches a predefined value.

• If it matches, print Access granted

• Otherwise print Access denied

9) Write a script that creates a backup of a given file.


The script should:
• Ask for a filename

• Copy it to <filename>.bak if it exists

• Otherwise print an error

10) Write a script that prints the largest of three numbers.


The script should:

• Ask the user for 3 numbers

• Print which one is the largest

Collect all bash scripts created in a folder and zip the folder then
upload it to LMS.

You might also like