0% found this document useful (0 votes)
675 views

Practice Exercises Shell Scripting Succinctly PDF

This document provides 8 practice exercises to learn shell scripting. The exercises incrementally build skills like printing messages, using variables, checking file properties, and accepting user input or arguments. They include hints on making scripts executable, using shebangs, variable syntax, and loops. The goal is to gain proficiency in core shell scripting tasks.
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)
675 views

Practice Exercises Shell Scripting Succinctly PDF

This document provides 8 practice exercises to learn shell scripting. The exercises incrementally build skills like printing messages, using variables, checking file properties, and accepting user input or arguments. They include hints on making scripts executable, using shebangs, variable syntax, and loops. The goal is to gain proficiency in core shell scripting tasks.
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
You are on page 1/ 2

Practice Exercises - Shell Scripting Succinctly

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

You might also like