{"id":243,"date":"2026-10-13T02:02:13","date_gmt":"2026-10-13T02:02:13","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2010\/04\/16\/interview-questions-sets-shell-script-descriptive\/"},"modified":"2026-10-13T02:02:13","modified_gmt":"2026-10-13T02:02:13","slug":"interview-questions-sets-shell-script-descriptive","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/interview-questions-sets-shell-script-descriptive\/","title":{"rendered":"Shell Scripting Interview Questions, Explained: Bash Fundamentals, UNIX Processes, and Practical Commands"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This revised guide turns the original long Q&amp;A into a practical reference for engineers preparing for Bash and UNIX interviews. It focuses on topics that show up in real DevOps work: scripting, command execution, redirection, permissions, and process control. Original post: <a href=\"https:\/\/www.devopsschool.com\/blog\/interview-questions-sets-shell-script-descriptive\/\">Shell Bash Scripting Interview Questions and Answer \u2013 Part 1<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Originally published on 2010-04-16; fully revised and updated.<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"400\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2010\/04\/interview-questions-sets-sh-1.png\" alt=\"shell-script-descriptive-interview-questions-sets\" class=\"wp-image-4304\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2010\/04\/interview-questions-sets-sh-1.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2010\/04\/interview-questions-sets-sh-1-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">What shell scripting is and why it matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Shell scripting means writing command-line instructions in a text file and running them through a shell interpreter such as <code>bash<\/code>, <code>sh<\/code>, or <code>ksh<\/code>. It is primarily used for automation on UNIX-like systems, and it often acts as glue between OS tools, CI jobs, and deployment scripts.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Automates repetitive admin tasks.<\/li><li>Combines existing tools quickly without compiling code.<\/li><li>Works well for bootstrapping, CI\/CD steps, and operational runbooks.<\/li><li>Can be risky when scripts are unquoted or run with destructive commands.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How a shell command executes under the hood<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Many interview questions around <code>fork<\/code>, <code>exec<\/code>, return codes, and zombies become easier once you understand the command lifecycle.<\/p>\n\n\n\n<pre class=\"mermaid\">\nflowchart TD\n    A[User enters command] --&gt; B[Shell parses tokens and expansions]\n    B --&gt; C{Builtin}\n    C -- yes --&gt; D[Run builtin in current shell]\n    C -- no --&gt; E[Fork child process]\n    E --&gt; F[Exec program in child]\n    F --&gt; G[Program exits with status]\n    D --&gt; H[Shell records exit code]\n    G --&gt; H\n    H --&gt; I[Prompt returns]\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the command is an external program, the shell usually creates a child process and then executes that program in the child. The exit code is returned to the shell, which makes it available as <code>$?<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Essential interview topics with practical command examples<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Exit codes and command chaining<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">By convention, exit code <code>0<\/code> means success and non-zero means failure. Operators like <code>&amp;&amp;<\/code> and <code>||<\/code> chain commands based on that status.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php language-bash\"><span class=\"hljs-comment\">#!\/usr\/bin\/env bash<\/span>\ngrep -q <span class=\"hljs-string\">\"ready\"<\/span> app.log\n<span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"Last exit code: $?\"<\/span>\n\ngrep -q <span class=\"hljs-string\">\"ready\"<\/span> app.log &amp;&amp; <span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"Service is ready\"<\/span> || <span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"Service is not ready\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Stdin, stdout, and stderr (file descriptors 0, 1, 2)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Standard input, output, and error are core to shell pipelines and logging strategy.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css language-bash\"><span class=\"hljs-selector-tag\">my_command<\/span> &gt;<span class=\"hljs-selector-tag\">stdout<\/span><span class=\"hljs-selector-class\">.log<\/span> 2&gt;<span class=\"hljs-selector-tag\">stderr<\/span><span class=\"hljs-selector-class\">.log<\/span>\n<span class=\"hljs-selector-tag\">my_command<\/span> &gt;<span class=\"hljs-selector-tag\">combined<\/span><span class=\"hljs-selector-class\">.log<\/span> 2&gt;&amp;1\n<span class=\"hljs-selector-tag\">my_command<\/span> &lt;<span class=\"hljs-selector-tag\">input<\/span><span class=\"hljs-selector-class\">.txt<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Executing a script vs sourcing a script<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Method<\/th><th>Typical syntax<\/th><th>Runs in current shell<\/th><th>Can change current shell environment<\/th><\/tr><\/thead><tbody><tr><td>Execute script<\/td><td><code>.\/script.sh<\/code><\/td><td>No<\/td><td>No<\/td><\/tr><tr><td>Source script<\/td><td><code>source .\/script.sh<\/code> or <code>. .\/script.sh<\/code><\/td><td>Yes<\/td><td>Yes<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php language-bash\"><span class=\"hljs-comment\"># env-demo.sh<\/span>\nexport DEMO_VALUE=<span class=\"hljs-string\">\"set-by-script\"<\/span>\n\n.\/env-demo.sh\n<span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"$DEMO_VALUE\"<\/span>    <span class=\"hljs-comment\"># usually empty in parent shell<\/span>\n\nsource .\/env-demo.sh\n<span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"$DEMO_VALUE\"<\/span>    <span class=\"hljs-comment\"># now visible in current shell<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Shebang and interpreter selection<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The shebang is the first line of an executable script and selects the interpreter.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php language-bash\"><span class=\"hljs-comment\">#!\/usr\/bin\/env bash<\/span>\nset -euo pipefail\n<span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"Running with Bash $BASH_VERSION\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Permissions, links, and file access fundamentals<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Interviewers frequently ask how to set permissions and how links behave in UNIX filesystems.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css language-bash\"><span class=\"hljs-selector-tag\">chmod<\/span> 664 <span class=\"hljs-selector-tag\">myfile<\/span>\n<span class=\"hljs-selector-tag\">chmod<\/span> <span class=\"hljs-selector-tag\">u<\/span>+<span class=\"hljs-selector-tag\">rwx<\/span>,<span class=\"hljs-selector-tag\">g<\/span>+<span class=\"hljs-selector-tag\">rx<\/span>,<span class=\"hljs-selector-tag\">o-rwx<\/span> <span class=\"hljs-selector-tag\">deploy<\/span><span class=\"hljs-selector-class\">.sh<\/span>\n<span class=\"hljs-selector-tag\">ls<\/span> <span class=\"hljs-selector-tag\">-l<\/span> <span class=\"hljs-selector-tag\">deploy<\/span><span class=\"hljs-selector-class\">.sh<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Link type<\/th><th>What it references<\/th><th>Cross-filesystem support<\/th><th>Typical command<\/th><\/tr><\/thead><tbody><tr><td>Hard link<\/td><td>Same inode as target file<\/td><td>No<\/td><td><code>ln file1 file2<\/code><\/td><\/tr><tr><td>Symbolic link<\/td><td>Path to another file or directory<\/td><td>Yes<\/td><td><code>ln -s file1 link1<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Command comparisons often asked in interviews<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Command<\/th><th>Comparison style<\/th><th>Best for<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td><code>cmp<\/code><\/td><td>Byte-by-byte; reports first mismatch<\/td><td>Quick binary or exact byte comparison<\/td><td><code>cmp fileA fileB<\/code><\/td><\/tr><tr><td><code>diff<\/code><\/td><td>Line-by-line differences<\/td><td>Text review and patch-style output<\/td><td><code>diff -u fileA fileB<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Process management, signals, daemons, and IPC<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Core process questions usually center on process IDs, states, and signaling. A daemon is a background service process detached from an interactive terminal session.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php language-bash\">sleep <span class=\"hljs-number\">300<\/span> &amp;\nBG_PID=$!\n\nps -p <span class=\"hljs-string\">\"$BG_PID\"<\/span> -o pid,ppid,stat,cmd\nkill <span class=\"hljs-string\">\"$BG_PID\"<\/span>      <span class=\"hljs-comment\"># graceful request<\/span>\nkill <span class=\"hljs-number\">-9<\/span> <span class=\"hljs-string\">\"$BG_PID\"<\/span>   <span class=\"hljs-comment\"># force kill if needed<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Common inter-process communication (IPC) mechanisms include unnamed pipes, named pipes (FIFO), sockets, message queues, and shared memory.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php language-bash\">mkfifo \/tmp\/demo.fifo\n\n<span class=\"hljs-comment\"># terminal 1<\/span>\ncat \/tmp\/demo.fifo\n\n<span class=\"hljs-comment\"># terminal 2<\/span>\n<span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"hello via fifo\"<\/span> &gt; \/tmp\/demo.fifo<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Login shells, non-login shells, and environment variables<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Startup files differ by shell implementation. The table below reflects common Bash behavior on Linux and UNIX-like systems.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Session type<\/th><th>Common Bash startup files<\/th><th>Typical use<\/th><\/tr><\/thead><tbody><tr><td>Login shell<\/td><td><code>\/etc\/profile<\/code>, then one of <code>~\/.bash_profile<\/code>, <code>~\/.bash_login<\/code>, or <code>~\/.profile<\/code><\/td><td>User environment initialization<\/td><\/tr><tr><td>Interactive non-login shell<\/td><td><code>~\/.bashrc<\/code><\/td><td>Aliases, prompt, interactive shell options<\/td><\/tr><tr><td>Non-interactive shell<\/td><td>May use <code>BASH_ENV<\/code> if set<\/td><td>Script-time environment setup<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php language-bash\"><span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"Login shell from env: $SHELL\"<\/span>\nps -p $$ -o comm=\nshopt -q login_shell &amp;&amp; <span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"login shell\"<\/span> || <span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"non-login shell\"<\/span>\n\nexport APP_ENV=prod\n<span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"$APP_ENV\"<\/span>\n<span class=\"hljs-keyword\">unset<\/span> APP_ENV<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Rapid-fire interview questions and concise answers<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>What does <code>$?<\/code> store?<\/strong> The exit status of the most recently executed command.<\/li><li><strong>What are file descriptors 0, 1, and 2?<\/strong> Standard input, standard output, and standard error.<\/li><li><strong>Difference between <code>\"$*\"<\/code> and <code>\"$@\"<\/code>?<\/strong> <code>\"$*\"<\/code> joins all positional parameters into one word; <code>\"$@\"<\/code> preserves each parameter as a separate word.<\/li><li><strong>What is <code>IFS<\/code>?<\/strong> The internal field separator used during word splitting.<\/li><li><strong>What is a zombie process?<\/strong> A terminated child process whose parent has not yet collected its exit status with <code>wait<\/code>.<\/li><li><strong>What does <code>exec<\/code> do in shell?<\/strong> Replaces the current shell process with the specified program.<\/li><li><strong>How do you make a script executable?<\/strong> Add execute permission, for example <code>chmod +x script.sh<\/code>.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best practices and common pitfalls<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Quote variable expansions (for example <code>\"$var\"<\/code>) to avoid word-splitting bugs.<\/li><li>Check exit codes and fail fast for automation workflows.<\/li><li>Use <code>set -euo pipefail<\/code> in Bash scripts where appropriate.<\/li><li>Be careful with destructive commands like <code>rm<\/code>, redirection, and wildcards.<\/li><li>Prefer explicit paths in cron\/CI contexts where environment variables differ.<\/li><li>Lint scripts with tools such as <code>shellcheck<\/code> before production use.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">A strong interview answer is not just a definition; it shows that you understand safe operational behavior, process control, and debugging in real shell automation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A modernized, interview-focused guide to shell scripting and core UNIX concepts for DevOps engineers. Learn command execution flow, redirection, permissions, process control, IPC, and safe scripting patterns with practical examples.<\/p>\n","protected":false},"author":1,"featured_media":4303,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[52],"tags":[641,3969,766,3968,3961,507,1553,482,1830,3910,138,3046,3960,3970,3966,3965,3964,3963,3967,3962,637],"class_list":["post-243","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-interview-questions-answers","tag-answers","tag-descriptive-shell-script-interview-question-and-answers","tag-interview","tag-interview-questions-answer-for-shell-script","tag-interview-questions-sets","tag-list","tag-most-asked","tag-questions","tag-selected","tag-sets","tag-shell","tag-shell-script","tag-shell-script-descriptive","tag-shell-script-descriptive-interview-question-and-answers","tag-shell-script-interview-guide","tag-shell-script-interview-qa","tag-shell-script-interview-questions-answers","tag-shell-script-job-interview","tag-shell-script-job-interview-kit","tag-shell-scripting-interview","tag-top"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=243"}],"version-history":[{"count":4,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/243\/revisions"}],"predecessor-version":[{"id":79073,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/243\/revisions\/79073"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/4303"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}