Practical List
Practical List
1. Write a shell script that prints “Shell Scripting is fun!” on the screen.
2. Store the output of the command “hostname” in a variable. Display “This script is running on
__” where “__” is the output of the “hostname” command.
3. Write a shell script to check to see if the file “file_path”exists. If it does exist, display
“file_path passwords are enabled”. Next, check to see if you can write to the file. If you can,
display “You have the permission to edit “file_path”. If you cannot, display “You do not have
the permission to edit “file_path”.
4. Write a shell script that displays “man”, “bear”,” pig”, “dog”, “cat” and “sheep” o the screen
with each appearing on a separate line.
5. Write a shell script that prompts the user for a name of a file or directory and reports if it is a
regular file, a directory or another type of file. Also run “ls” command against the file or
directory with the long listing option.
6. Write the shell script that displays, “This script will exit with 0 exit status.” Be sure that the
script does indeed exit with a 0 exit status.
7. Write a shell script that accepts a file or directory name as an argument. Have the script report
if it is regular file, a directory, or another type of file. If it is a directory, exit with a 1exit status.
If it is some other type of file, exit with a 2 exit status.
8. Write a script that executes the command “cat/etc/shadow”. If the command returns a 0 exit
status, report “command succeeded” and exit with a 0 exit status. If the command returns a non-
zero exit status, report “command failed” and exit with a 1 exit status.
9. Write a shell script that consists of a function that displays the number of files in the present
working directory. Name this function “file_count” and call it in your script. If you use variable
in your function, remember to make it a local variable.
10. Write the shell script that renames all files in the current directory that ends in “.jpg” to begin
with today’s date in the following format: YYYY-MM-DD. For example, if a picture of a cat
was in the current directory and today was May 07, 2023 it would change the name from
“mycat.jpg” to “2023-05-07-mycat.jpg”.
11. Write the shell script that displays one random number on the screen and also generates a
system log message with that random number. Use the “user” facility and “info” facility for your
messages.
12. Write a shell script that exits on error and displays commands as they will execute, including
all expansions and substitutions. Use 3 ls commands in your script. Make the first one succeed,
the second one fail, and third one succeeds. If you are using the proper options, the third ls
command not be executed.