TutorialPedia.org
Toggle Menu
Home
Online Go Compiler
Tutorials
JavaScript Tutorials
Golang Tutorials
Linux Command Line Tutorials
Blog
All Posts
Linux Scripting with Bash
Test your ability to automate tasks using shell scripts and variables.
1. What is the standard shebang line to specify a Bash script?
#!/bin/bash
#!/bash
#!/bin/sh
#!bash
2. Which is the correct way to assign a value to a variable in Bash (no spaces)?
name = "John"
name="John"
set name "John"
name := "John"
3. Which loop runs as long as a condition is true?
for
until
while
do-while
4. What does $? represent in Bash?
Number of arguments
Exit status of last command
Current script name
Home directory
5. Which syntax captures command output into a variable?
$(command)
{command}
<command>
!command
6. Which operator checks if a file is a regular file?
-d
-f
-e
-x
7. What terminates a case statement?
end
esac
done
fi
8. How to declare an array in Bash?
arr = (1 2 3)
array arr=(1 2 3)
arr=(1 2 3)
set arr = (1 2 3)
9. What exit status indicates command success?
0
1
255
-1
10. Which variable holds the script name?
$1
$0
$#
$@
11. Valid Bash loop structures:
for
while
do-while
until
12. Check if a file exists:
[ -e "file.txt" ]
test -e "file.txt"
[[ -e "file.txt" ]]
exists "file.txt"
13. Reference command-line arguments:
$1
$@
$*
$#
14. Valid conditional constructs:
if...then...fi
switch...case...end
case...esac
select...in...do...done
15. Bash functions must be defined before use.
True
False
16. 'break' exits the entire script.
True
False
17. Backticks (`) work for command substitution like $(...).
True
False
18. Command to read user input into a variable (no options):
19. Symbol to start a comment line (single character):
20. Variable with all arguments as separate elements:
Reset
Answered 0 of 0 — 0 correct