1. On Ubuntu, what does /bin/sh usually point to?
- dash
- bash
- zsh
- fish
जवाब देखें
जवाब: dash
Debian and Ubuntu use dash as /bin/sh for speed and strict POSIX behaviour.
पाठ: What Bash Is
Bash / Shell Scripting कोर्स के 25 सवाल, हर सवाल के सही जवाब और explanation के साथ। जवाब देखने से पहले ख़ुद सोचें।
जवाब: dash
Debian and Ubuntu use dash as /bin/sh for speed and strict POSIX behaviour.
पाठ: What Bash Is
जवाब: The command succeeded
By convention, 0 means success and non-zero means some kind of failure.
जवाब: A separate process cannot change the working directory of the parent shell
Each process has its own working directory; only the shell itself can change its own.
जवाब: count=3
Bash assignments must not have spaces around the equals sign.
जवाब: rm receives two arguments, "my" and "file.txt"
Unquoted expansion undergoes word splitting on the space.
जवाब: report.tar
% removes the shortest matching suffix, so only ".gz" is removed.
पाठ: Parameter Expansion, Command Substitution and Arithmetic
जवाब: (( n > 10 ))
Arithmetic evaluation compares numbers; > inside [[ ]] compares strings and inside [ ] is a redirection.
जवाब: Only if cmd1 fails
|| runs the right-hand command only when the left-hand one returns a non-zero status.
जवाब: It preserves spaces and backslashes exactly as they appear in each line
Empty IFS keeps surrounding whitespace and -r stops backslash interpretation.
जवाब: Print it and let the caller capture it with $(function)
return only sets a numeric status; data is returned by printing to stdout.
जवाब: "${arr[@]}"
"${arr[@]}" expands each element as its own word, preserving spaces inside elements.
जवाब: -e takes a value, which is placed in $OPTARG
A colon after an option letter means that option requires an argument.
जवाब: ./build.sh > build.log 2>&1
Redirect stdout to the file first, then point stderr at the same place.
जवाब: 0, because the status of the last command is used
By default a pipeline returns the status of its last command; pipefail changes that.
जवाब: jq
jq parses JSON structurally; text tools break when formatting changes.
जवाब: The status of the line is that of the local builtin, which succeeds
local returns its own success status, masking the command substitution's failure; declare and assign separately.
जवाब: trap cleanup EXIT
The EXIT pseudo-signal fires whenever the shell exits, for any reason it can handle.
जवाब: Prints each command after expansion before running it
Tracing shows the exact expanded commands, which is invaluable for debugging.
जवाब: SIGKILL
SIGKILL (9) terminates immediately; it cannot be trapped, which is why it is a last resort.
जवाब: A rename within one file system is atomic, so readers never see a partially written file
Atomic rename guarantees readers see either the complete old or complete new file.
पाठ: Safe File Handling
जवाब: cron runs with a minimal environment: short PATH, no profile and a different working directory
The stripped-down environment breaks scripts that rely on interactive settings.
जवाब: The whole file is parsed before anything runs, and the structure is clearer
Calling main at the bottom ensures every function is defined first and guards against partial execution.
जवाब: The script has grown to hundreds of lines with nested data structures and floating-point maths
Complex data and logic are where Bash becomes error-prone and hard to maintain.
जवाब: Without pipefail, a failed pg_dump would be hidden by gzip's successful exit status
The pipeline status would otherwise come from gzip, masking a failed dump.
जवाब: other_cmd "$@"
"$@" expands each argument as its own word, preserving spaces inside arguments.