0
0
Bash Scriptingscripting~10 mins

Creating a script file (.sh) in Bash Scripting - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a bash script with the correct shebang line.

Bash Scripting
#![1]
echo "Hello, world!"
Drag options to blanks, or click blank then click option'
A/bin/bash
B/usr/bin/python
C/bin/sh
D/usr/bin/perl
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong interpreter path like /usr/bin/python.
Forgetting the #! at the start of the line.
2fill in blank
medium

Complete the command to make the script file executable.

Bash Scripting
chmod [1] myscript.sh
Drag options to blanks, or click blank then click option'
A-r
B+x
C+r
D-w
Attempts:
3 left
💡 Hint
Common Mistakes
Using -r or -w which remove read or write permissions.
Using +r which only adds read permission, not execute.
3fill in blank
hard

Fix the error in the script to print the current directory.

Bash Scripting
echo "Current directory is: [1]"
Drag options to blanks, or click blank then click option'
A`PWD`
BPWD
C$PWD()
D$PWD
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the $ sign before PWD.
Using PWD as a command instead of a variable.
4fill in blank
hard

Fill both blanks to create a script that prints all arguments passed to it.

Bash Scripting
echo "Arguments: [1]"
for arg in [2]; do
  echo "$arg"
done
Drag options to blanks, or click blank then click option'
A"$@"
B$*
C"$*"
D$@
Attempts:
3 left
💡 Hint
Common Mistakes
Using $* which treats all arguments as one string.
Quoting $@ in the loop which breaks iteration.
5fill in blank
hard

Fill all three blanks to create a script that checks if a file exists and prints a message.

Bash Scripting
if [[ [1] [2] [3] ]]; then
  echo "File exists."
else
  echo "File not found."
fi
Drag options to blanks, or click blank then click option'
A-f
Bmyfile.txt
C-d
Dfile.txt
Attempts:
3 left
💡 Hint
Common Mistakes
Using -d which checks for directories, not files.
Using the wrong filename or missing quotes if needed.