Bash¶
86 cards β π’ 23 easy | π‘ 47 medium | π΄ 1 hard
π’ Easy (23)¶
1. How do you append the output of a command to a file?
Show answer
Using the >> operator.Remember: > overwrites the file, >> appends to it. Mnemonic: one arrow = one shot (overwrite), two arrows = add more.
Example: echo 'new line' >> logfile.txt adds without destroying existing content. Use > only when you want a fresh file.
2. How do you make a shell script executable?
Show answer
Give it execute permission (e.g., chmod +x script.sh) and ensure it has a proper shebang (#!/bin/bash) if run by name.Example: #!/usr/bin/env bash is preferred over #!/bin/bash β env finds bash in $PATH for portability.
Name origin: 'sharp' (#) + 'bang' (!) = shebang. Also called hashbang.
Remember: cut -d',' -f1 extracts the first comma-separated field. -d sets delimiter, -f selects fields. For complex parsing, prefer awk.
3. What is the ternary operator? How do you use it in bash?
Show answer
A short way of using if/else. An example:[[ $a = 1 ]] && b="yes, equal" || b="nope"
Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
4. How do you run a command in the background in Bash?
Show answer
Append an ampersand (&) to the command (e.g., ./long_task & runs long_task in the background).Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
5. How can you create a temporary file safely in a script?
Show answer
By using the mktemp utility.Gotcha: always quote variables in bash: "$var" prevents word splitting and glob expansion. Unquoted variables are the #1 source of bash bugs.
Remember: bash is powerful but fragile. Use shellcheck (shellcheck.net) to catch common errors. It finds bugs that even experienced developers miss.
6. What does the $? variable store?
Show answer
The exit status of the last executed command.Remember: $? = exit status of last command. 0 = success, non-zero = failure. Convention: 1 = general error, 2 = misuse, 126 = not executable, 127 = not found.
7. How do you run a command in the background?
Show answer
By appending an & to the end of the command.Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
8. How do you perform arithmetic operations in Bash?
Show answer
Using the $((...)) syntax or the expr command.Gotcha: always quote variables in bash: "$var" prevents word splitting and glob expansion. Unquoted variables are the #1 source of bash bugs.
Remember: bash is powerful but fragile. Use shellcheck (shellcheck.net) to catch common errors. It finds bugs that even experienced developers miss.
9. How do you define a local variable within a Bash function?
Show answer
By using the local keyword.Remember: variables are global by default in bash. Use 'local' keyword inside functions to limit scope. Missing 'local' = accidental side effects.
10. How do you get the value of the first argument in a Bash script?
Show answer
Use $1 (similarly, $2 for second, etc., and $@ for all arguments).Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
11. What is Bash and why is it the default shell on most Linux systems?
Show answer
Bash (Bourne Again SHell) is a Unix shell and command language used as the default shell on many Linux systems; it allows running commands and scripting to automate tasks.Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
12. What does the export command do in Bash?
Show answer
It marks a shell variable to be passed to child processes as an environment variable (e.g., export VAR=value).Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
13. Tell me about your scripting background.
Show answer
Bash is my strongest language β I've written everything from automation frameworks to custom DSLs for managing large server fleets. I focus on clean logic, predictable behavior, safe defaults, and portability. I've also used Python and Perl for tasks where stronger data structures or libraries were needed.Remember: for complex text processing, consider Python over bash. Bash excels at file operations and command orchestration; Python excels at data manipulation and error handling.
14. What is difference between $@ and $*?
Show answer
`$@` is an array of all the arguments passed to the script`$*` is a single string of all the arguments passed to the script
Example: with args 'hello world' and 'foo': "$@" = two args ('hello world', 'foo'). "$*" = one arg ('hello world foo'). Always use "$@" to preserve argument boundaries.
Remember: for complex text processing, consider Python over bash. Bash excels at file operations and command orchestration; Python excels at data manipulation and error handling.
15. How do you get the number of arguments passed to a Bash script?
Show answer
$# expands to the count of positional parameters (arguments) passed to the script.Example: sed -i 's/old/new/g' file.txt replaces all occurrences in-place. -i flag edits the file directly (use -i.bak for backup).
16. How do you check the exit status of the last command in Bash?
Show answer
$? contains the exit status (0 means success, non-zero indicates an error).Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
17. How do you do arithmetic in Bash?
Show answer
Using arithmetic expansion or the expr command. For example, result=$((2+2)) sets result to 4.Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
18. How can you capture the output of a command into a variable in Bash?
Show answer
Use command substitution: either backticks `command` or $(command) (e.g., RESULT=`uname -r` or RESULT=$(uname -r)).Example: files=$(ls *.txt) captures output. $() nests cleanly: $(echo $(date)). Preferred over backticks.
Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
19. What is the difference between > and >> in Bash redirection?
Show answer
> redirects output to a file (overwriting it), whereas >> appends the output to the end of the file (without overwriting existing content).Remember: > = stdout to file, 2> = stderr to file, &> = both to file, 2>&1 = stderr to where stdout goes. Order matters!
Example: command > output.log 2>&1 captures both stdout and stderr. command 2>&1 > file sends stderr to terminal, stdout to file (probably not what you want).
20. What does the | (pipe) operator do?
Show answer
Passes the output of one command as input to another command.Remember: pipe (|) connects stdout of left command to stdin of right command. Data flows left to right. Like UNIX Lego blocks.
Example: ps aux | grep nginx | awk '{print $2}' | xargs kill β find nginx PIDs and kill them. Each | is a handoff.
21. What is the output of echo '$HOME' in bash?
Show answer
The literal string $HOME. Single quotes suppress all expansion.Gotcha: always quote variables in bash: "$var" prevents word splitting and glob expansion. Unquoted variables are the #1 source of bash bugs.
Remember: bash is powerful but fragile. Use shellcheck (shellcheck.net) to catch common errors. It finds bugs that even experienced developers miss.
22. Why does x = 2 fail but x=2 works in bash?
Show answer
Bash interprets x = 2 as running a command called x with arguments = and 2. Variable assignment requires no spaces around the equals sign.Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
23. Why prefer $(...) over backticks for command substitution?
Show answer
$(...) nests cleanly, is easier to read, and avoids confusing escaping rules. Backticks are legacy syntax.Example: files=$(ls *.txt) captures output. $() nests cleanly: $(echo $(date)). Preferred over backticks.
Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
π‘ Medium (47)¶
1. How do you run a script in the current shell environment?
Show answer
Use the source command (or .) like source script.sh (runs the script in the current shell, so its environment changes persist).Remember: source script.sh (or . script.sh) runs in the current shell β variables and functions persist after execution. ./script.sh runs in a subshell β changes are lost.
Gotcha: sourcing a script that calls 'exit' will close your current terminal! Use 'return' in sourced scripts instead of 'exit.'
2. Generate 8 digit random number
Show answer
shuf -i 10000000-99999999 -n 1Example: $RANDOM gives a random integer 0-32767. For larger ranges, use shuf, /dev/urandom, or openssl rand. shuf is the simplest for integer ranges.
3. How do you debug shell scripts?
Show answer
Answer depends on the language you are using for writing your scripts. If Bash is used for example then:* Adding -x to the script I'm running in Bash
* Old good way of adding echo statements
If Python, then using pdb is very useful.
Remember: for complex text processing, consider Python over bash. Bash excels at file operations and command orchestration; Python excels at data manipulation and error handling.
4. What command is used for security audits and network scanning?
Show answer
nmap (Network Mapper). It discovers hosts, open ports, running services, and OS versions on a network. Common usage: `nmap -sV -sCExample: sed -i 's/old/new/g' file.txt replaces all occurrences in-place. -i flag edits the file directly (use -i.bak for backup).
5. What does ${VAR:=VALUE} accomplish?
Show answer
It assigns VALUE to VAR only if VAR is unset or null.Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
6. In shell scripting, how to check if a given argument is a number?
Show answer
```\nregex='^[0-9]+$'\nif [[ ${var//*.} =~ $regex ]]; then\n...\n```Gotcha: always quote variables in bash: "$var" prevents word splitting and glob expansion. Unquoted variables are the #1 source of bash bugs.
Remember: bash is powerful but fragile. Use shellcheck (shellcheck.net) to catch common errors. It finds bugs that even experienced developers miss.
7. How to define a variable with the value of the current date?
Show answer
`DATE=$(date)` β uses command substitution to run the `date` command and store its output (e.g., 'Tue Mar 18 14:00:00 UTC 2026') in the variable DATE. You can also use backtick syntax: DATE=`date`.Remember: for complex text processing, consider Python over bash. Bash excels at file operations and command orchestration; Python excels at data manipulation and error handling.
8. How to compare variables length?
Show answer
```\nif [ ${#1} -ne ${#2} ]; then\n ...\n```Gotcha: always quote variables in bash: "$var" prevents word splitting and glob expansion. Unquoted variables are the #1 source of bash bugs.
Remember: bash is powerful but fragile. Use shellcheck (shellcheck.net) to catch common errors. It finds bugs that even experienced developers miss.
9. How to define a variable with the value "Hello World"?
Show answer
`HW="Hello World`Gotcha: always quote variables in bash: "$var" prevents word splitting and glob expansion. Unquoted variables are the #1 source of bash bugs.
Remember: bash is powerful but fragile. Use shellcheck (shellcheck.net) to catch common errors. It finds bugs that even experienced developers miss.
10. What is the difference between running a script with ./script.sh vs source script.sh?
Show answer
./script.sh executes the script in a new subshell (changes don't affect the caller's environment), whereas source script.sh executes it in the current shell (so any exported variables or directory changes remain in your session).Remember: source script.sh (or . script.sh) runs in the current shell β variables and functions persist after execution. ./script.sh runs in a subshell β changes are lost.
Gotcha: sourcing a script that calls 'exit' will close your current terminal! Use 'return' in sourced scripts instead of 'exit.'
11. How do you make maintainable Bash scripts?
Show answer
Error handling (set -euo pipefail), small functions, validation, logging, and clear separation between config and logic. If a script grows too large, I rewrite it in Python.Gotcha: set -e exceptions β commands in if/&&/|| do NOT trigger exit. Combine with set -o pipefail.
Example: set -euo pipefail = recommended strict mode (error, undefined vars, pipe failures).
Remember: for complex text processing, consider Python over bash. Bash excels at file operations and command orchestration; Python excels at data manipulation and error handling.
12. How do you represent a single quote in an awk statement?
Show answer
By using the octal code \047.Example: awk '{print $1, $3}' file.txt prints columns 1 and 3. awk -F: '{print $1}' /etc/passwd prints usernames.
13. True or False? When a certain command/line fails in a shell script, the shell script, by default, will exit and stop running
Show answer
Depends on the language and settings used.If the script is a bash script then this statement is true. When a script written in Bash fails to run a certain command it will keep running and will execute all other commands mentioned after the command which failed.
Most of the time we might actually want the opposite to happen. In order to make Bash exist when a specific command fails, use 'set -e' in your script.
Remember: for complex text processing, consider Python over bash. Bash excels at file operations and command orchestration; Python excels at data manipulation and error handling.
14. Write a script to print "yay" unless an argument was passed and then print that argument
Show answer
```\necho "${1:-yay}"\n```Example: sed -i 's/old/new/g' file.txt replaces all occurrences in-place. -i flag edits the file directly (use -i.bak for backup).
15. What is the purpose of the : command in Bash?
Show answer
It is a null command that does nothing but returns success (0).Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
16. What does this line in shell scripts means?: #!/bin/bash
Show answer
`#!/bin/bash` is She-bang/bin/bash is the most common shell used as default shell for user login of the linux system. The shellβs name is an acronym for Bourne-again shell. Bash can execute the vast majority of scripts and thus is widely used because it has more features, is well developed and better syntax.
Remember: #!/usr/bin/env bash is more portable than #!/bin/bash. It finds bash in PATH, handling systems where bash is in /usr/local/bin.
17. Running the following bash script, we don't get 2 as a result, why?
Show answer
Should be `x=2`Gotcha: always quote variables in bash: "$var" prevents word splitting and glob expansion. Unquoted variables are the #1 source of bash bugs.
Remember: bash is powerful but fragile. Use shellcheck (shellcheck.net) to catch common errors. It finds bugs that even experienced developers miss.
18. How to extract everything after the last dot in a string?
Show answer
`${var##*.}` β this parameter expansion removes everything up to and including the last dot, leaving only the final extension. For example, if var='archive.tar.gz', then ${var##*.} yields 'gz'.Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
19. What does set -u or set -o nounset do?
Show answer
It causes the script to exit if an unset variable is referenced.Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
20. How do you get input from the user in shell scripts?
Show answer
Using the keyword `read` so for example `read x` will wait for user input and will store it in the variable x.Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
21. How to check if a given number has 4 as a factor?
Show answer
`if [ $(($1 % 4)) -eq 0 ]; then`Gotcha: always quote variables in bash: "$var" prevents word splitting and glob expansion. Unquoted variables are the #1 source of bash bugs.
Remember: bash is powerful but fragile. Use shellcheck (shellcheck.net) to catch common errors. It finds bugs that even experienced developers miss.
22. What does read -r do?
Show answer
Reads input without allowing backslashes to escape characters.Gotcha: always quote variables in bash: "$var" prevents word splitting and glob expansion. Unquoted variables are the #1 source of bash bugs.
Remember: bash is powerful but fragile. Use shellcheck (shellcheck.net) to catch common errors. It finds bugs that even experienced developers miss.
23. How do you make Bash scripts safe?
Show answer
Defense in depth:**Strict mode**:
```bash\nset -euo pipefail\n```
* `-e`: Exit on error
* `-u`: Error on undefined variables
* `-o pipefail`: Pipe fails if any command fails
**Traps for cleanup**:
```bash\ntrap 'rm -f "$tmpfile"' EXIT\n```
**Explicit paths**:
```bash\nPATH=/usr/local/bin:/usr/bin:/bin\n```
**Validate inputs**:
```bash\n[[ -z "${1:-}" ]] && { echo "Usage: $0
**Logging**:
```bash\nexec > >(tee -a "$logfile") 2>&1\n```
**Parameter expansion safety**:
```bash\nrm -rf "${dir:?dir not set}"/*\n```
The most dangerous script is the one run with confidence and no backup.
Remember: for complex text processing, consider Python over bash. Bash excels at file operations and command orchestration; Python excels at data manipulation and error handling.
24. How do you check the settings of a Network Interface Card (NIC)?
Show answer
ethtool. It queries and controls NIC settings: `ethtool eth0` shows speed/duplex/link, `ethtool -i eth0` shows driver info, `ethtool -S eth0` shows NIC-level counters.Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
25. How to perform arithmetic operations on numbers?
Show answer
One way: `$(( 1 + 2 ))`Another way: `expr 1 + 2`
Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
26. What would be the output of the following script?
Show answer
Michelangelo β the script outputs this name because the associative array or indexed variable lookup resolves to this value based on the index/key used in the print or echo statement.Remember: for complex text processing, consider Python over bash. Bash excels at file operations and command orchestration; Python excels at data manipulation and error handling.
27. Today we have tools and technologies like Ansible, Puppet, Chef, ... Why would someone still use shell scripting?
Show answer
* Speed* Flexibility
* The module we need doesn't exist (perhaps a weak point because most CM technologies allow to use what is known as "shell" module)
* We are delivering the scripts to customers who don't have access to the public network and don't necessarily have Ansible installed on their systems.
Remember: for complex text processing, consider Python over bash. Bash excels at file operations and command orchestration; Python excels at data manipulation and error handling.
28. What do && and || do in Bash command execution?
Show answer
cmd1 && cmd2 runs cmd2 only if cmd1 succeeds (exit status 0). cmd1 || cmd2 runs cmd2 only if cmd1 fails (non-zero exit status).Remember: cut -d',' -f1 extracts the first comma-separated field. -d sets delimiter, -f selects fields. For complex parsing, prefer awk.
29. What does the following code do and when would you use it?
Show answer
It is called 'process substitution'. It provides a way to pass the output of a command to another command when using a pipe `|` is not possible. It can be used when a command does not support `STDIN` or you need the output of multiple commands.https://superuser.com/a/1060002/167769
Remember: for complex text processing, consider Python over bash. Bash excels at file operations and command orchestration; Python excels at data manipulation and error handling.
30. What does set -e do in a Bash script?
Show answer
It enables errexit mode β the script will exit immediately if any command returns a non-zero (error) status.Gotcha: set -e has exceptions β commands in if/&&/|| do NOT trigger exit. Combine with set -o pipefail for safer scripts.
Example: set -euo pipefail is the recommended strict mode preamble (exit on error, undefined vars, pipe failures).
Remember: set -euo pipefail is the 'strict mode' trinity: -e (exit on error), -u (undefined vars are errors), -o pipefail (pipe failures propagate).
Gotcha: set -e does NOT catch errors in if conditions, || chains, or command substitutions. Use explicit error handling for critical sections.
31. What's the difference between an environment variable and a shell variable?
Show answer
A shell variable is local to the current shell session, whereas an environment variable is exported and available to child processes. (You use export to turn a shell variable into an environment variable.)Remember: for complex text processing, consider Python over bash. Bash excels at file operations and command orchestration; Python excels at data manipulation and error handling.
32. When do you stop using Bash?
Show answer
Bash is glue, not an application framework. Stop when:**State grows**: Managing complex data structures, nested objects β use Python/Go.
**Complexity grows**: More than ~200 lines, multiple files β real language.
**Error handling matters**: Bash error handling is clunky. If reliability is critical, use something better.
**Portability needed**: Bash versions differ. POSIX sh is safer but limited.
**Testing required**: Bash testing is possible but painful. Real languages have real test frameworks.
**Good use cases for Bash**:
* Glue scripts (calling other tools)
* Simple automation
* One-off tasks
* Boot scripts, init
Bash should connect things, not BE the thing.
33. How do you change the priority of a running process?
Show answer
renice. It adjusts the nice value of a running process: `renice -n 10 -pGotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
34. What separates good Bash from bad?
Show answer
The basics that most scripts get wrong:**Quoting**: Always quote variables. `"$var"` not `$var`. Unquoted variables break on spaces and glob.
**Error handling**: Check return codes. Use `set -e` or explicit checks. Don't assume commands succeed.
**Idempotence**: Running twice should be safe. Check before acting.
**Readability**: Clear variable names, comments for non-obvious logic, consistent formatting.
**Bad script**:
```bash\nrm -rf $dir/*\n```
**Good script**:
```bash\nset -euo pipefail\nif [[ -d "$dir" ]]; then\n rm -rf "${dir:?}"/*\nfi\n```
If you can't read your script in 6 months, it's bad Bash.
Remember: for complex text processing, consider Python over bash. Bash excels at file operations and command orchestration; Python excels at data manipulation and error handling.
35. What is the primary advantage of the [[ keyword over [?
Show answer
It supports regular expressions and is less prone to word-splitting errors.Remember: file tests: -f (regular file), -d (directory), -e (exists), -r (readable), -w (writable), -x (executable), -s (non-empty). String tests: -z (empty), -n (non-empty).
36. How to extract everything before the last dot in a string?
Show answer
${var%.*} β uses bash parameter expansion. The `%` operator removes the shortest match of `.*` from the end. For greedy (last dot): `${var%%.*}`.Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
37. How to print the first argument passed to a script?
Show answer
`echo $1` β `$1` is the first positional parameter. `$0` is the script name, `$#` is the argument count, and `$@` expands to all arguments.Example: sed -i 's/old/new/g' file.txt replaces all occurrences in-place. -i flag edits the file directly (use -i.bak for backup).
38. What does 2>&1 signify?
Show answer
Redirects standard error (stderr) to standard output (stdout).Remember: > = stdout to file, 2> = stderr to file, &> = both to file, 2>&1 = stderr to where stdout goes. Order matters!
Example: command > output.log 2>&1 captures both stdout and stderr. command 2>&1 > file sends stderr to terminal, stdout to file (probably not what you want).
39. What is the purpose of the trap command?
Show answer
To execute a command or function when the script receives a signal.Example: trap 'rm -f /tmp/lockfile' EXIT ensures cleanup on exit, even on error/Ctrl+C.
Example: trap 'rm -f /tmp/lockfile' EXIT ensures cleanup runs even if the script fails. Trap signals: EXIT, ERR, INT, TERM.
40. What do you tend to include in every script you write?
Show answer
Few example:* Comments on how to run it and/or what it does
* If a shell script, adding "set -e" since I want the script to exit if a certain command failed
You can have an entirely different answer. It's based only on your experience and preferences.
Remember: for complex text processing, consider Python over bash. Bash excels at file operations and command orchestration; Python excels at data manipulation and error handling.
41. What expansions occur inside double quotes in bash?
Show answer
Variable expansion ($VAR, ${VAR}) and command substitution ($(...)) occur. Globbing and word splitting do not.Example: files=$(ls *.txt) captures output. $() nests cleanly: $(echo $(date)). Preferred over backticks.
Remember: 'single quotes' = literal (no expansion). "double quotes" = expands $variables and $(commands). Use double quotes almost always to prevent word splitting.
42. What does set -o pipefail do and why is it needed beyond set -e?
Show answer
Without pipefail, a pipeline's exit status is the last command's status. With pipefail, the pipeline fails if ANY command in the pipe fails. set -e alone misses mid-pipe failures.Gotcha: set -e exceptions β commands in if/&&/|| do NOT trigger exit. Combine with set -o pipefail.
Example: set -euo pipefail = recommended strict mode (error, undefined vars, pipe failures).
Remember: set -euo pipefail is the 'strict mode' trinity: -e (exit on error), -u (undefined vars are errors), -o pipefail (pipe failures propagate).
Gotcha: set -e does NOT catch errors in if conditions, || chains, or command substitutions. Use explicit error handling for critical sections.
43. Why does bash if test the exit status of a command rather than a boolean expression?
Show answer
Because bash is a shell language first. if runs a command and branches on its exit code (0 = true, non-zero = false). [ and [[ are commands/keywords that evaluate expressions and return exit codes.Remember: [ is a command (test), [[ is a bash keyword (more features). Use [[ for pattern matching, regex, and safer quoting.
44. What two dangers arise from leaving a variable unquoted in bash?
Show answer
Word splitting (spaces in the value become separate arguments) and filename globbing (wildcards like * expand to matching files). Both can cause unexpected behavior or security issues.Gotcha: bash scripts should start with set -euo pipefail for strict error handling. Without it, errors silently continue, producing wrong results.
45. What are the advantages of using RAID (Redundant Array of Independent Disks) in a server environment?
Show answer
RAID is a technology that combines multiple physical disk drives into a single logical unit for the purpose of data redundancy, improved performance, or both. The advantages of using RAID in a server environment include: **Data Redundancy:* β’ RAID provides fault tolerance by duplicating or parity-checking data across multiple drives. In the event of a drive failure, data can be reconstructed from the redundancy, ensuring data integrity and availability .Example: arr=(a b c); echo ${arr[0]} prints 'a'. ${arr[@]} expands all elements. ${#arr[@]} gives the count.
46. Explain the concept of LUN (Logical Unit Number) in storage management.
Show answer
A Logical Unit Number (LUN) is a unique identifier assigned to a logical unit, which is a representation of a subset of a storage subsystem. In storage management, a LUN is typically associated with storage area networks (SANs) and is used to define a logical volume or unit of storage presented to a server. **Key points about LUNs include:* β’ β’ Identification: A LUN is identified by a number or address that allows a server to access a specific portion of storage within a storage array.47. Discuss the steps you would take to recover data from a failed storage device.
Show answer
β’ Assess the Failure: Determine the nature of the storage failure (logical, physical, or both). β’ Isolate the Device: Isolate the failed storage device to prevent further damage or data loss. β’ Verify Backups: Confirm the availability and integrity of recent backups. β’ Use Data Recovery Tools: Explore data recovery tools that may be able to recover data from the failed storage device. β’ Engage Data Recovery Services: If necessary, consider engaging professional data recovery services for physical damage or complex issues.π΄ Hard (1)¶
1. Name a situation where set -e does NOT cause the script to exit on error.
Show answer
Commands in the condition of an if statement, commands in a pipeline (without pipefail), commands after && or ||, and commands inside $(...) subshells do not trigger errexit. This is why set -e should be used carefully, not superstitiously.Remember: set -euo pipefail is the 'strict mode' trinity: -e (exit on error), -u (undefined vars are errors), -o pipefail (pipe failures propagate).
Gotcha: set -e does NOT catch errors in if conditions, || chains, or command substitutions. Use explicit error handling for critical sections.