[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-1-en-105":3,"doc-seo-571884-105":53,"doc-detail-571884-en":127},{"code":4,"msg":5,"data":6},0,"success",[7,14,19,24,29,34,39,44,49],{"id":8,"doc_module":9,"doc_module_name":10,"category_name":11,"show_sort_weight":12,"slug":13},11,1,"Template","Presentations",90,"presentations",{"id":15,"doc_module":9,"doc_module_name":10,"category_name":16,"show_sort_weight":17,"slug":18},12,"Resumes",80,"resumes",{"id":20,"doc_module":9,"doc_module_name":10,"category_name":21,"show_sort_weight":22,"slug":23},14,"Invoices",70,"invoices",{"id":25,"doc_module":9,"doc_module_name":10,"category_name":26,"show_sort_weight":27,"slug":28},15,"Posters",60,"posters",{"id":30,"doc_module":9,"doc_module_name":10,"category_name":31,"show_sort_weight":32,"slug":33},16,"Social Media",50,"social-media",{"id":35,"doc_module":9,"doc_module_name":10,"category_name":36,"show_sort_weight":37,"slug":38},17,"Forms",40,"forms",{"id":40,"doc_module":9,"doc_module_name":10,"category_name":41,"show_sort_weight":42,"slug":43},18,"Letters",30,"letters",{"id":45,"doc_module":9,"doc_module_name":10,"category_name":46,"show_sort_weight":47,"slug":48},21,"Paper Templates",5,"papers-templates",{"id":50,"doc_module":9,"doc_module_name":10,"category_name":51,"show_sort_weight":4,"slug":52},158,"General","general-158",{"code":4,"msg":54,"data":55},"ok",{"site_id":56,"language":57,"slug":58,"title":59,"keywords":60,"description":61,"schema_data":62,"social_meta":120,"head_meta":122,"extra_data":124,"updated_unix":126},105,"en","bash-quick-reference-script-variables-control-flow","Bash - Quick reference - Script, variables, control flow","","Quick reference covering everyday Bash scripting fundamentals, including running scripts, variable assignment and defaults, quoting rules and safe printf usage, positional script arguments, and using tests with exit status. Explains integer arithmetic, branching with case, loop constructs, and defining functions with local scope. Adds practical guidance for indexed arrays, command substitution, pipeline failure detection, input/output redirection, environment and scope, safe line reading, globbing and filenames, temporary files with traps, and parsing short options using getopts.",{"@graph":63,"@context":119},[64,80,102],{"@type":65,"itemListElement":66},"BreadcrumbList",[67,71,74,77],{"item":68,"name":69,"@type":70,"position":9},"https://docshare.wps.com","Home","ListItem",{"item":72,"name":10,"@type":70,"position":73},"https://docshare.wps.com/template/",2,{"item":75,"name":11,"@type":70,"position":76},"https://docshare.wps.com/template/presentations/",3,{"item":78,"name":59,"@type":70,"position":79},"https://docshare.wps.com/template/bash-quick-reference-script-variables-control-flow/571884/",4,{"url":78,"name":59,"@type":81,"image":82,"author":87,"headline":59,"publisher":90,"fileFormat":93,"inLanguage":57,"description":61,"dateModified":94,"datePublished":95,"encodingFormat":93,"isAccessibleForFree":96,"interactionStatistic":97},"DigitalDocument",{"url":83,"@type":84,"width":85,"height":86},"https://docshare.wps.com/thumbnails/bash-quick-reference-script-variables-control-flow/571884.png","ImageObject",442,249,{"name":88,"@type":89},"WPS_1786070896","Person",{"url":68,"name":91,"@type":92},"DocShare","Organization","application/pdf","2026-10-23","2026-10-13",true,{"@type":98,"interactionType":99,"userInteractionCount":101},"InteractionCounter",{"@type":100},"ViewAction",8,{"@type":103,"mainEntity":104},"FAQPage",[105,111,115],{"name":106,"@type":107,"acceptedAnswer":108},"How can you run a Bash script and check syntax without executing commands?","Question",{"text":109,"@type":110},"Use bash [hello.sh] to run the script. Use bash-n [hello.sh] to check syntax without running commands.","Answer",{"name":112,"@type":107,"acceptedAnswer":113},"What is the difference between ${var:-word} and ${var-word} in Bash?",{"text":114,"@type":110},"${var:-word} provides a default when the variable is unset or empty. ${var-word} uses the default only when the variable is unset.",{"name":116,"@type":107,"acceptedAnswer":117},"How do you detect failures in a pipeline in Bash?",{"text":118,"@type":110},"Enable set -o pipefail, then check the pipeline status explicitly. pipefail reports the rightmost failure or zero.","https://schema.org",{"og:url":78,"og:type":121,"og:title":59,"og:site_name":91,"og:description":61},"article",{"robots":123,"canonical":78},"index,follow",{"doc_id":125,"site_id":56},571884,1792014837,{"code":4,"msg":5,"data":128},{"doc_id":125,"user_id":129,"nickname":88,"user_avatar":130,"doc_module":9,"category_id":8,"category_name":11,"doc_title":59,"doc_description":61,"doc_content":131,"file_id":132,"file_url":133,"file_type":134,"file_size":135,"view_count":101,"is_deleted":4,"is_public":9,"is_downloadable":9,"audit_status":9,"page_count":73,"language":136,"language_code":57,"site_id":56,"html_lang":57,"table_of_contents":137,"faqs":138,"seo_title":139,"seo_description":61,"update_tm":140,"read_time":9},549768072016,"https://ap-avatar.wpscdn.com/davatar_155a257f0dc6eb9ab79c44ca47cae57d","QUICK REFERENCE / BASH  \nBash Scripts, expansion, and everyday flow.  \n  DevSheets  \n01 / LANGUAGE & CONTROL FLOW  \n 01  Run a Bash script  \n\\#!/usr/bin/env bash  \nname=Maya  \nprintf 'Hello, %s!\\n' \"$name\"  \nprintf 'Bash: %s\\n' \"$BASH_VERSION\"exit 0  \nSave as hello.sh; run bash [hello.sh](hello.sh). bash-n [hello.sh](hello.sh) checks syntax without running commands. Examples are independent Bash scripts, not portable sh. Zero exit status means success.  \n 02  Variables & defaults  \nname= \"Maya Chen\"  \ncount=3  \nprintf '%s: %s\\n' \"$name\" \"$count\"label=${title:-Untitled}  \nprintf '%s\\n' \"$label\"  \nunset count  \nAssignments have no spaces around =. ${var:-word} defaultsunset or empty values; ${var-word} only defaults unset values. Scalar assignments store text by default.  \n 03  Quoting & printf  \nname= \"Maya Chen\"  \nliteral= '$name stays literal'printf '%s\\n' \"$name\"  \nprintf '%s\\n' \"$literal\"  \nprintf '%s\\n' '100% ready'  \nDouble quotes expand variables without word splitting orglobbing. Single quotes keep literal text. Quote expansions by default. Use a fixed printf format with values as arguments.  \n 04  Script arguments  \nprintf 'Script: %s\\n' \"$0\"  \nprintf 'Count: %s\\n' \"$\\#\"first=${1:-Guest}  \nprintf 'First: %s\\n' \"$first\"for arg in \"$@\" ; do  \nprintf 'Arg: %s\\n' \"$arg\"done  \n\"$@\" preserves each argument, including empty ones. \"$*\"joins them into one word. ${10} accesses argument ten. shift removes the first argument; check that one exists.  \n 05  Tests & exit status  \nname=Maya  \nif [[ -n \"$name\" && \"$name\" == Maya ]]; then printf '%s\\n' 'Name found'  \nfi  \nfalse; status=$?  \nprintf 'Status: %s\\n' \"$status\"  \n[[ ... ]] is a Bash conditional: -n means nonempty, -z empty, -f regular file, -d directory. Quote the right side of == for a literal string. Capture $? before another command replaces it.  \n 06  Integer arithmetic  \ncount=3  \n((count += 1))  \nwhole=$((7 / 2)) rest=$((7 % 2))  \nprintf '%s\\n' \"$count\" \"$whole\" \"$rest\"  \n$((...)) expands an integer. ((...)) returns status 0 for nonzero, 1 for zero. Division truncates. Use constants or validated numbers, never untrusted arithmetic text.  \n 07  Branches & case  \nmode=dev  \ncase \"$mode\" in  \ndev|test) printf '%s\\n' 'Local' ;; prod) printf '%s\\n' 'Production' ;;*) printf '%s\\n' 'Unknown' >&2 ;;  \nesac  \ncase matches shell patterns; | separates alternatives and * catches anything. ;; ends a branch. if/elif/else branches on command status, including tests, and ends with fi.  \n 08  Loops  \nfor name in Maya Leo; do printf '%s\\n' \"$name\"  \ndone  \nleft=2  \nwhile ((left > 0)); do left=$((left - 1))  \ndone  \nfor visits words or array items. while repeats on success; until repeats on failure. break exits a loop; continue skips ahead. Quote expanded values to preserve each item.  \n 09  Functions & local values  \ngreet() {  \nlocal name=${1:-Guest}  \nprintf 'Hello, %s!\\n' \"$name\"}  \ngreet \"Maya Chen\"  \nFunctions use their own positional arguments. local limits variable scope inside functions. return reports status (0-255); use stdout for text results. exit ends the script.  \nQUICK REFERENCE / BASH  \nBash Collections, commands, and safe I/O.  \n  DevSheets  \n02 / SHELL TOOLS & PRACTICAL I/O  \n 10  Indexed arrays  \nnames=(\"Maya Chen\" \"Leo\")  \nnames+=(\"Sam\")  \nprintf 'Count: %s\\n' \"${\\#names[@]}\"  \nprintf 'First: %s\\n' \"${names[0]}\"  \nprintf '%s\\n' \"${names[@]}\"  \nArrays preserve separate elements. \"${names[@]}\" expands one word per item, including empty strings. unset 'names[1]'removes an element without reindexing the others.  \n 11  Command substitution  \nif stamp=$(date +%F); then printf 'Today: %s\\n' \"$stamp\"  \nelse  \nprintf '%s\\n' 'date failed' >&2 exit 1  \nfi  \n$(command) captures stdout and removes trailing newlines. Quote its result. Assignment alone reports the substitution's status. Do not use substitution to split lists of filenames.  \n 12  Pipelines & failures  \nset -o pipefail  \nif printf '%s\\n' red blue | grep red; then printf '%s\\n' 'Matched'  \nelse  \nstatus=$?  \nprintf 'Pi","cbCaigfk184Ttt2e","https://ap.wps.com/l/cbCaigfk184Ttt2e","pdf",80076,"English","# 01 / LANGUAGE & CONTROL FLOW\n## 01  Run a Bash script\n## 02  Variables & defaults\n## 03  Quoting & printf\n## 04  Script arguments\n## 05  Tests & exit status\n## 06  Integer arithmetic\n## 07  Branches & case\n## 08  Loops\n## 09  Functions & local values\n# 02 / SHELL TOOLS & PRACTICAL I/O\n## 10  Indexed arrays\n## 11  Command substitution\n## 12  Pipelines & failures\n## 13  Redirect input & output\n## 14  Environment & scope\n## 15  Read text safely\n## 16  Globs & filenames\n## 17  Temporary files & cleanup\n## 18  Parse short options","[{\"question\":\"How can you run a Bash script and check syntax without executing commands?\",\"answer\":\"Use bash [hello.sh] to run the script. Use bash-n [hello.sh] to check syntax without running commands.\"},{\"question\":\"What is the difference between ${var:-word} and ${var-word} in Bash?\",\"answer\":\"${var:-word} provides a default when the variable is unset or empty. ${var-word} uses the default only when the variable is unset.\"},{\"question\":\"How do you detect failures in a pipeline in Bash?\",\"answer\":\"Enable set -o pipefail, then check the pipeline status explicitly. pipefail reports the rightmost failure or zero.\"}]","Bash - Quick reference - Script, variables, control flow | PDF",1791924228]