[{"id":"bashadvanced-001","courseId":"bash-advanced","domain":"syntax-and-commands","topic":"Exit status 127 for unknown commands","prompt":"A script runs deploy-tool --check, but no file called deploy-tool exists in any directory listed on PATH. What exit status does the failed command return?","hint":"Each kind of failure has its own reserved number, so the value depends on why the command failed.","explain":"A zero status means success, and a nonzero status means failure. Bash reserves particular values for particular failure situations, so the number tells you why the command failed.","source":"https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html","interaction":{"type":"single"},"options":[{"id":"a","text":"127","why":"When a command is not found, the child process Bash creates to run it returns 127."},{"id":"b","text":"126","whyNot":"126 is for a command that is found but is not executable."},{"id":"c","text":"1","whyNot":"Plain 1 is not the value Bash documents for a missing command; that case has its own reserved number."},{"id":"d","text":"128","whyNot":"128 is not the value for a missing command; Bash uses 128 plus a signal number only when a command dies from a fatal signal."}],"answer":"a","explanation":"A command that cannot be found makes its child process return 127; Bash reserves specific statuses for specific failure modes.","concept":"A command that cannot be found makes its child process return 127; Bash reserves specific statuses for specific failure modes.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"deploy-tool --check\necho $?","takeaways":["Status 127 means the command was not found; 126 means it was found but cannot be executed."]},{"id":"bashadvanced-002","courseId":"bash-advanced","domain":"syntax-and-commands","topic":"Exit status 126 for non-executable files","prompt":"A teammate runs ./report.sh. The file exists but lacks execute permission, and Bash returns the same status, 127, that it returns for a missing command.","hint":"Think about whether Bash found the file before it failed to run it.","explain":"Bash can fail to run a command in different ways, and each way gets its own reserved status. Ask whether the shell located the file at all before it tried to execute it.","source":"https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"A command that is found but not executable returns 126; 127 is for a command that cannot be found."},{"id":"b","text":"False","why":"Bash finds ./report.sh, so the failure is a non-executable one, and that case returns 126, not 127."}],"answer":"b","explanation":"A command that is found but is not executable returns 126, while a command that cannot be found returns 127.","concept":"A command that is found but is not executable returns 126, while a command that cannot be found returns 127.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Found but not executable gives 126; not found gives 127."]},{"id":"bashadvanced-003","courseId":"bash-advanced","domain":"syntax-and-commands","topic":"Exit status 128+N for fatal signals","prompt":"A long compile runs in the foreground of a script. Someone sends it SIGTERM, which is signal 15, and it dies. What exit status does Bash report for that command?","hint":"Consider how the shell encodes a command that ended on a signal rather than by exiting.","explain":"A process killed by a signal never reaches its own exit code, so the shell needs a status that identifies the signal. Statuses stay within the usual range of values a process can return.","source":"https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html","interaction":{"type":"single"},"options":[{"id":"a","text":"143","why":"Bash uses 128 plus the signal number for a command killed by a fatal signal, so 128 + 15 is 143."},{"id":"b","text":"15","whyNot":"15 is the signal number itself; Bash adds 128 to it before reporting the status."},{"id":"c","text":"128","whyNot":"128 is not enough by itself; the signal number has to be added to it."},{"id":"d","text":"-15","whyNot":"Exit statuses fall between 0 and 255, so Bash does not report a negative value."}],"answer":"a","explanation":"A command that terminates on a fatal signal N makes Bash use 128+N as its exit status.","concept":"A command that terminates on a fatal signal N makes Bash use 128+N as its exit status.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["A status of 128 plus N means the command died from signal N; all statuses stay within 0 to 255."]},{"id":"bashadvanced-004","courseId":"bash-advanced","domain":"syntax-and-commands","topic":"lastpipe option","prompt":"A script runs shopt -s lastpipe, then a pipeline with job control off whose last command is read line. Where can that last command run?","hint":"Ask which process normally runs each pipeline element, then what lastpipe changes about the last one.","explain":"Pipeline elements usually run in separate processes, so a variable set inside one is lost when the pipeline ends. Shell options can change that default, and job control affects whether the change applies.","source":"https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html","interaction":{"type":"single"},"options":[{"id":"a","text":"In the current shell, so variables it sets stay set afterward.","why":"With lastpipe on and job control off, the last element may be run by the shell process itself."},{"id":"b","text":"In its own subshell, like every other element of the pipeline.","whyNot":"Each element of a multi-command pipeline normally gets its own subshell; lastpipe can make the last one an exception."},{"id":"c","text":"In the background, so the pipeline returns before read finishes.","whyNot":"lastpipe does not make a pipeline asynchronous; a pipeline not run asynchronously waits for all its commands."},{"id":"d","text":"In the current shell, but only when pipefail is also enabled.","whyNot":"pipefail only changes how the pipeline's exit status is computed, not where its commands run."}],"answer":"a","explanation":"With lastpipe enabled and job control inactive, the last element of a pipeline may run in the shell process rather than a subshell.","concept":"With lastpipe enabled and job control inactive, the last element of a pipeline may run in the shell process rather than a subshell.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"shopt -s lastpipe\nprintf 'hi\\n' | read line\necho $line","takeaways":["lastpipe lets the last pipeline element set variables in the current shell when job control is off."]},{"id":"bashadvanced-005","courseId":"bash-advanced","domain":"syntax-and-commands","topic":"time keyword with pipelines","prompt":"A teammate runs the command below, where build_all is a shell function. Which TWO statements about the time keyword here are true?","hint":"Think about what the reserved word measures and what kinds of command it can be placed in front of.","explain":"The time keyword is part of the shell, placed in front of a command rather than run as a separate tool. Consider what unit of work it reports, and what kinds of command it can time.","source":"https://www.gnu.org/software/bash/manual/html_node/Pipelines.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"It prints timing statistics for the whole pipeline once the pipeline finishes.","why":"Bash prints timing statistics for the pipeline once it finishes."},{"id":"b","text":"It can time build_all, a shell function, which an external time command cannot easily do.","why":"Using time as a reserved word lets it time shell functions, builtins and pipelines."},{"id":"c","text":"It prints one separate timing line for build_all and another for tee.","whyNot":"The statistics are for the pipeline as one unit, not for each command separately."},{"id":"d","text":"It reports only the last command in the pipeline, which is tee.","whyNot":"The statistics cover the pipeline as a whole, not only its final command."},{"id":"e","text":"Its -p flag switches it to showing only elapsed time.","whyNot":"-p only changes the output format to the one POSIX specifies."},{"id":"f","text":"It works only in POSIX mode, where time is a reserved word.","whyNot":"time is a reserved word in general; POSIX mode only changes how it treats a following dash."}],"answer":"ab","explanation":"The time reserved word times a whole pipeline, including shell functions and builtins, and prints statistics once the pipeline finishes.","concept":"The time reserved word times a whole pipeline, including shell functions and builtins, and prints statistics once the pipeline finishes.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"time build_all | tee build.log","takeaways":["time before a pipeline reports one set of statistics for the whole pipeline.","As a reserved word, time can time functions and builtins, which an external time command cannot easily do."]}]