Basic Scripting Concepts Flashcards
7 cards from real 010-160 practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Basic Scripting Concepts flashcards as text
What does the `-z` test operator check in `[ -z "$var" ]`?
Answer: Whether $var is an empty string
`-z` returns true when the string has a length of zero.
Which command substitution syntax is POSIX-compatible and preferred in modern scripts?
Answer: $(command)
`$(command)` is the modern, nestable form of command substitution recommended by POSIX.
What value does `$#` represent in a shell script?
Answer: The number of positional parameters passed
`$#` expands to the count of positional parameters supplied when the script was invoked.
How do you make a script file executable so it can be run as `./myscript.sh`?
Answer: chmod +x myscript.sh
`chmod +x` adds the execute permission bit, allowing the file to be run directly.
In bash, what is the correct way to compare two integer variables `a` and `b` for equality inside `[ ]`?
Answer: [ $a -eq $b ]
`-eq` is the arithmetic equality operator used inside `[ ]` for numeric comparisons.
Which construct runs a block of commands repeatedly as long as a condition is TRUE?
Answer: while loop
A `while` loop evaluates its condition before each iteration and continues as long as it is true.
What happens if you use `local` to declare a variable inside a bash function?
Answer: The variable is only visible within the function
`local` restricts the variable's scope to the function and its children, preventing pollution of the global namespace.