Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to run a script named myscript.sh in the current directory.
Bash Scripting
./[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to use
./ before the script name.Using the wrong script file name.
✗ Incorrect
To run a script in the current directory, prefix the script name with
./ followed by the script file name.2fill in blank
mediumComplete the command to make the script myscript.sh executable.
Bash Scripting
chmod [1] myscript.sh Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
chmod rwx which sets permissions but not correctly.Using
chmod -x which removes execute permission.✗ Incorrect
The command
chmod +x filename adds execute permission to the file.3fill in blank
hardFix the error in the command to run myscript.sh with bash explicitly.
Bash Scripting
bash [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting
./ causing 'file not found' error.Using script name without extension.
✗ Incorrect
To run a script with bash explicitly, provide the relative or absolute path including
./ if in current directory.4fill in blank
hardFill both blanks to create a script that prints 'Hello' and then exits with status 0.
Bash Scripting
#!/bin/bash echo [1] exit [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the string, causing errors.
Using exit status other than 0 for success.
✗ Incorrect
Use quotes around the string to print it correctly. Exit status 0 means success.
5fill in blank
hardFill all three blanks to create a script that takes one argument and prints it.
Bash Scripting
#!/bin/bash input=[1] echo [2] exit [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
$0 which is the script name, not the argument.Not exiting with 0 to indicate success.
✗ Incorrect
Use
$1 to get the first argument, print the variable, and exit with 0 for success.