[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-1-en-105":3,"doc-seo-573358-105":53,"doc-detail-573358-en":126},{"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":119,"head_meta":121,"extra_data":123,"updated_unix":125},105,"en","devhintsio-bash-shell-scripting-snippets","DevHints.io - Bash Shell Scripting Snippets","","DevHints.io provides a collection of Bash shell scripting examples and mini-snippets focused on variable handling, parameter expansion, and string slicing. It demonstrates echo usage with dynamic variables, commit error handling, and Git command fallback patterns. The text covers shell comments, multi-line comments, file and path manipulation, and conditional tests using [[ ]] and arithmetic comparisons. It also includes array creation and mutation, loops (for and C-style), pipelines, and shell option configuration with set -o and shopt.",{"@graph":63,"@context":118},[64,80,101],{"@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/devhintsio-bash-shell-scripting-snippets/573358/",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/devhintsio-bash-shell-scripting-snippets/573358.png","ImageObject",442,249,{"name":88,"@type":89},"Patrick","Person",{"url":68,"name":91,"@type":92},"DocShare","Organization","application/pdf","2026-10-18","2026-10-14",true,{"@type":98,"interactionType":99,"userInteractionCount":79},"InteractionCounter",{"@type":100},"ViewAction",{"@type":102,"mainEntity":103},"FAQPage",[104,110,114],{"name":105,"@type":106,"acceptedAnswer":107},"How does the document show parameter expansion and string slicing in Bash?","Question",{"text":108,"@type":109},"It uses examples like ${name:0:2} for slicing and substitutions such as ${name/J/j} for replacement. It also demonstrates length-based slicing and right-side indexing.","Answer",{"name":111,"@type":106,"acceptedAnswer":112},"What conditional forms are included for checking strings and file existence?",{"text":113,"@type":109},"It shows tests using [[ -z STRING ]] and [[ -n STRING ]] for empty/non-empty strings, along with comparisons like == and !=. It also includes file checks such as [[ -e \"file.txt\" ]] and regex matching with =~.",{"name":115,"@type":106,"acceptedAnswer":116},"How are arrays handled and iterated in the examples?",{"text":117,"@type":109},"The document demonstrates array initialization and indexed access (e.g., ${Fruits[0]}). It includes operations like push/append, unset to remove elements, and looping through arrays with for i in \"${array[@]}\". Shell options and globs are also configured via set -o and shopt.","https://schema.org",{"og:url":78,"og:type":120,"og:title":59,"og:site_name":91,"og:description":61},"article",{"robots":122,"canonical":78},"index,follow",{"doc_id":124,"site_id":56},573358,1792014484,{"code":4,"msg":5,"data":127},{"doc_id":124,"user_id":128,"nickname":88,"user_avatar":129,"doc_module":9,"category_id":8,"category_name":11,"doc_title":59,"doc_description":61,"doc_content":130,"file_id":131,"file_url":132,"file_type":133,"file_size":134,"view_count":79,"is_deleted":4,"is_public":9,"is_downloadable":9,"audit_status":9,"page_count":79,"language":135,"language_code":57,"site_id":56,"html_lang":57,"table_of_contents":136,"faqs":137,"seo_title":138,"seo_description":61,"update_tm":139,"read_time":73},549758146520,"https://ap-avatar.wpscdn.com/avatar/80002397d8c0411e94?_k=1775819394049821470","\\#!/usr/bin/env bash  \nNAME= \"John\"  \necho \"Hello $NAME!\"  \nNAME= \"John\"echo $NAME  \necho \"$NAME\"  \necho \"${NAME} !\"  \ngit commit || echo \"Commit failed\"  \nname= \"John\"echo ${name}  \necho ${name/J/j} \\#=> \"john\" (substitution) echo ${name :0 :2} \\#=> \"Jo\" (slicing)  \necho ${name : :2} \\#=> \"Jo\" (slicing)  \necho ${name : :-1} \\#=> \"Joh\" (slicing)  \necho ${name :(-1)} \\#=> \"n\" (slicing from right) echo ${name :(-2) :1} \\#=> \"h\" (slicing from right) echo ${food :-Cake} \\#=> $food or \"Cake\"  \n\n| length=2\u003Cbr>echo ${name :0 :length} \\#=> \"Jo\" |\n| --- |\n| |\n\n\"/ h/ /f \"  \n\\# Single line comment  \n'  \n:  \nThis is a multi line comment  \n'  \nSTR= pat to oo .cpp  \necho ${STR% .cpp} \\# /path/to/foo  \necho ${STR% .cpp} .o \\# /path/to/foo .o  \necho ${STR%/*} \\# /path/to  \necho ${STR\\#\\#* .} \\# cpp (extension)  \necho ${STR\\#\\#*/} \\# foo .cpp (basepath)  \necho ${STR\\#*/}  \necho ${STR\\#\\#*/}  \n\\# path/to/foo .cpp  \n\\# foo .cpp  \necho ${STR/foo/bar} \\# /path/to/bar .cpp  \nSTR= \"Hello world\"  \necho ${STR:6 :5} \\# \"world\"  \necho ${STR : -5 :5} \\# \"world\"  \nSRC= \"/path/to/foo .cpp\"  \nBASE=${SRC\\#\\#*/} \\#=> \"foo .cpp\" (basepath) DIR=${SRC%$BASE} \\#=> \"/path/to/ \" (dirpath)  \nfor i in /etc/rc .* ; do echo $i  \ndone  \nfor ((i = 0 ; i \u003C 100 ; i++)); do echo $i  \ndone  \ncat file .txt | while read line; do echo $line  \ndone  \n[[ 0  1   \ngrep(1)  ping(1)  \n\n| [[ -z STRING ]] | |\n| --- | --- |\n| [[ -n STRING ]] | |\n| [[ STRING == STRING ]] | |\n| [[ STRING != STRING ]] | |\n| [[ NUM -eq NUM ]] | |\n| [[ NUM -ne NUM ]] | |\n| [[ NUM -lt NUM ]] | |\n| [[ NUM -le NUM ]] | |\n| [[ NUM -gt NUM ]] | |\n| [[ NUM -ge NUM ]] | |\n| [[ STRING =~ STRING ]] | |\n| (( NUM \u003C NUM )) | |\n| |  |\n| [[ -o noclobber ]] | |\n| [[ ! EXPR ]] | |\n| [[ X && Y ]] | |\n\n[[ X || Y ]]  \n\\# String  \nif [[ -z \"$string\" ]]; then echo \"String is empty\"  \nelif [[ -n \"$string\" ]]; then echo \"String is not empty\"  \nelse  \necho \"This never happens\"  \nfi  \n\n| \\# Combinations\u003Cbr>if [[ X && Y ]]; then. . .\u003Cbr>fi |\n| --- |\n| \\# Equal\u003Cbr>if [[ \"$A\" == \"$B\" ]] |\n| \\# Regex\u003Cbr>if [[ \"A\" =~ . ]] |\n\nif (( $a \u003C $b )); then  \necho \"$a is smaller than $b\"  \nfi  \nif [[ -e \"file .txt\" ]]; then echo \"file exists\"  \nfi  \nFruits= ( 'Apple ' 'Banana ' 'Orange ' )  \nFruits [0]= \"Apple\"Fruits [1]= \"Banana\"Fruits [2]= \"Orange\"  \necho ${Fruits [0]}  \necho ${Fruits [-1]}  \necho ${Fruits [@]}  \necho ${\\#Fruits [@]}  \necho ${\\#Fruits}  \necho ${\\#Fruits [3]}  \necho ${Fruits [@] :3 :2}  \necho ${!Fruits [@]}  \n\\# Element \\#0  \n\\# Last element  \n\\# All elements, space-separated  \n\\# Number of elements  \n\\# String length of the 1st element  \n\\# String length of the Nth element  \n\\# Range (from position 3, length 2)  \n\\# Keys of all elements, space-separated  \nFruits= ( \"${Fruits [@]} \" \"Watermelon\" ) \\# Push  \nFruits+=( 'Watermelon ' ) \\# Also Push  \nFruits= ( ${Fruits [@]/Ap*/} ) \\# Remove by regex match  \nunset Fruits [2] \\# Remove one item  \nFruits= ( \"${Fruits [@]} \" ) \\# Duplicate  \nFruits= ( \"${Fruits [@]} \" \"${Veggies [@]} \" ) \\# Concatenate lines= ( `cat \"logfile\" `) \\# Read from file  \nfor i in \"${arrayName[@]} \" ; do echo $i  \ndone  \nset -o noclobber \\# Avoid overlay files (echo \"hi\" > foo)  \nset -o errexit \\# Used to exit upon error, avoiding cascading errors set -o pipefail \\# Unveils hidden failures  \nset -o nounset \\# Exposes unset variables  \nshopt -s nullglob \\# Non-matching globs are removed ( '* .foo ' => ' ' )  \nshopt -s failglob \\# Non-matching globs throw errors  \nshopt -s nocaseglob \\# Case insensitive globs  \nshopt -s dotglob \\# Wildcards match dotfiles (\"*.sh\" => \".[foo.sh](foo.sh)\") shopt -s globstar \\# Allow ** for recursive matches ( 'lib/**/* .rb ' => 'lib  \n GLOBIGNORE   \nhistory  \n!$  \n!$ :h   \n! !  !$   \n!$   \n\n| ! ! :n-m  |\n| --- |\n| ! ! :n-$  n |\n\n! !  !cat !-2 !42  \ncommand -V cd  \n\\#=> \"cd is a function/alias/whatever\"  \npython hello .py \u003C foo .txt \\# feed foo .txt to stdin for python  \ntrap 'echo Error at about $LINENO ' ERR  \ntraperr() {  \necho \"ERROR : ${BASH_SOURCE[1]} at about ${BASH_LINENO[0]","cbCaigaqwU3OXDEZ","https://ap.wps.com/l/cbCaigaqwU3OXDEZ","pdf",2180472,"English","# Bash Basics\n## Variables and Echo\n## Parameter Expansion\n## Comments\n## Path Manipulation\n## Arrays and Loops\n## Conditionals and Shell Options","[{\"question\":\"How does the document show parameter expansion and string slicing in Bash?\",\"answer\":\"It uses examples like ${name:0:2} for slicing and substitutions such as ${name/J/j} for replacement. It also demonstrates length-based slicing and right-side indexing.\"},{\"question\":\"What conditional forms are included for checking strings and file existence?\",\"answer\":\"It shows tests using [[ -z STRING ]] and [[ -n STRING ]] for empty/non-empty strings, along with comparisons like == and !=. It also includes file checks such as [[ -e \\\"file.txt\\\" ]] and regex matching with =~.\"},{\"question\":\"How are arrays handled and iterated in the examples?\",\"answer\":\"The document demonstrates array initialization and indexed access (e.g., ${Fruits[0]}). It includes operations like push/append, unset to remove elements, and looping through arrays with for i in \\\"${array[@]}\\\". Shell options and globs are also configured via set -o and shopt.\"}]","DevHints.io - Bash Shell Scripting Snippets | PDF",1791938000]