Guided Exercices
Guided Exercices
the screen
#!/bin/bashecho “Shell Scripting is Fun!”
Output
[svimukthi@sanka Shell_Scripting]$ ./exe1.sh
Shell Scripting is Fun!
The variable will hold the contents of the message “Shell Scripting is
Fun!”
#!/bin/bash
NAME=”Shell Scripting is Fun!”
echo $NAME
Output
[svimukthi@sanka Shell_Scripting]$ ./exe2.sh
Shell Scripting is Fun!
Output
[svimukthi@sanka Shell_Scripting]$ ./exe3.sh
This script is running on vimukthi
Exercise_4 - Write a shell script to check to see if the file “file_path”
check to see if you can write to the file. If you can, display “You have
#!/bin/bashFILE=”/home/svimukthi/Assignment/sanka”if [ -e “$FILE”
]
then
echo “$FILE passwords are enabled”
fiif [ -x “$FILE” ]
then
echo “You have permition to execute $FILE” else
echo “You do Not have permissions to execute $FILE”
fi
Output
[svimukthi@sanka Shell_Scripting]$ ./exe4.sh
/home/svimukthi/Assignment/sanka passwords are enabled
You have permition to execute /home/svimukthi/Assignment/sanka
#!/bin/bash
ANIMALS=”man bear pig dog cat sheep”
for ANIMAL in $ANIMALS
do
echo $ANIMAL
done
Output
[svimukthi@sanka Shell_Scripting]$ ./exe5.sh
man
bear
pig
dog
cat
sheep
Exercise_6 - write a shell script that prompts the user for a name of a file
of file. Also perform an ls command against the file or directory with the
Output
[svimukthi@sanka Shell_Scripting]$ ./exe6.sh
Enter the file path
/home/svimukthi/sanka
/home/svimukthi/sanka is a directory
total 4
drwxr-xr-x. 2 svimukthi svimukthi 30 Nov 13 20:18 hs
-rw-rw-r — . 1 svimukthi svimukthi 12 Nov 12 12:09 sanka.txt
d — x — — — . 2 svimukthi svimukthi 20 Dec 13 18:53 test
Exercise_7 - Modify the previous script to that it accepts the file or
#!/bin/bash
FILE=$1
if [ -f “$FILE” ]
then
echo “$FILE is a reguler file”
elif [ -d “$FILE” ]
then
echo “$FILE is a directory”
else
echo “$FILE is another type of file”
fils -l $FILE
Output
[svimukthi@sanka Shell_Scripting]$ ./exe7.sh
/home/svimukthi/sanka
/home/svimukthi/sanka is a directory
total 4
drwxr-xr-x. 2 svimukthi svimukthi 30 Nov 13 20:18 hs
-rw-rw-r — . 1 svimukthi svimukthi 12 Nov 12 12:09 sanka.txt
d — x — — — . 2 svimukthi svimukthi 20 Dec 13 18:53 test
#!/bin/bash
FILES=$@
for FILE in $FILES
do
if [ -f “$FILE” ]
then
echo “$FILE is a reguler file”
elif [ -d “$FILE” ]
then
echo “$FILE is a directory”
else
echo “$FILE is another type of file”
fi
ls -l $FILE done
Output
[svimukthi@sanka Shell_Scripting]$ ./exe8.sh
/home/svimukthi/sanka /hms/apps
/home/svimukthi/sanka is a directory
total 4
drwxr-xr-x. 2 svimukthi svimukthi 30 Nov 13 20:18 hs
-rw-rw-r — . 1 svimukthi svimukthi 12 Nov 12 12:09 sanka.txt
d — x — — — . 2 svimukthi svimukthi 20 Dec 13 18:53 test
/hms/apps is a directory
total 60
drwx — — — . 7 svimukthi svimukthi 4096 Dec 7 15:08 ajuba
drwx — — — . 7 svimukthi svimukthi 4096 Dec 7 15:08 ajuba-
preference-data-loader
drwx — — — . 7 svimukthi svimukthi 4096 Nov 30 10:25 ajuba-survey
-rw-rw-r — . 1 svimukthi svimukthi 22772 Dec 10 17:01 sendKindle-
2.1–6.el7.psychotic.noarch.rpm
-rw-rw-r — . 1 svimukthi svimukthi 19875 Dec 10 17:04 sendKindle-
2.1–6.el7.psychotic.src.rpm
drwxr-xr-x. 2 svimukthi svimukthi 4096 Dec 17 08:24
Versions_Script