Practice Exercises Shell Scripting Succinctly PDF
Practice Exercises Shell Scripting Succinctly PDF
Exercise 1:
Writeashellscriptthatprints"ShellScriptingisFun!"tothescreen.
Hint1:
Remembertomaketheshellscriptexecutablewiththechmodcommand.
Hint2:
Remembertostartyourscriptwithashebang!
Exercise 2:
Modifytheshellscriptfromexercise1toincludeavariable.Thevariablewillholdthecontents
ofthemessage"ShellScriptingisFun!".
Exercise 3:
Storetheoutputofthecommand"hostname"inavariable.Display"Thisscriptisrunningon
_______."where"_______"istheoutputofthe"hostname"command.
Hint:
It'sabestpracticetousethe${VARIABLE}syntaxifthereistextorcharactersthatdirectly
preceedorfollowthevariable.
Exercise 4:
Writeashellscripttochecktoseeifthefile"/etc/shadow"exists.Ifitdoesexist,display
"Shadowpasswordsareenabled."Next,checktoseeifyoucanwritetothefile.Ifyoucan,
display"Youhavepermissionstoedit/etc/shadow."Ifyoucannot,display"YoudoNOThave
permissionstoedit/etc/shadow."
LinuxTrainingAcademy.com
Exercise 5:
Writeashellscriptthatdisplays"man","bear","pig","dog","cat",andsheeptothescreenwith
eachappearingonaseparateline.Trytodothisinasfewlinesaspossible.
Hint:Loopscanbeusedtoperformrepetitivetasks.
Exercise 6:
Writeashellscriptthatpromptstheuserforanameofafileordirectoryandreportsifitisa
regularfile,adirectory,orothertypeoffile.
Alsoperformanlscommandagainstthefileordirectorywiththelonglistingoption.
Exercise 7:
Modifythepreviousscriptsothatitacceptsthefileordirectorynameasanargumentinsteadof
promptingtheusertoenterit.
Exercise 8:
Modifythepreviousscripttoacceptanunlimitednumberoffilesanddirectoriesasarguments.
Hint:You'llwanttouseaspecialvariable.
LinuxTrainingAcademy.com