[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-1-en-105":3,"doc-seo-571886-105":53,"doc-detail-571886-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","bash-cheat-sheet-level-3-control-structure","BASH cheat sheet-Level 3 - Control Structure","","BASH cheat sheet - Level 3 provides practical reference for Bash control structures and common language constructs. It explains conditional statements using if/elif/else and the case statement for matching values against patterns. The guide covers file tests, string and arithmetic comparisons, logical operators, and pattern matching. It also summarizes loop techniques (for/while), file reading patterns, and core array and hash usage, along with basic script elements, arguments, functions, and simple user menus.",{"@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/bash-cheat-sheet-level-3-control-structure/571886/",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-cheat-sheet-level-3-control-structure/571886.png","ImageObject",442,249,{"name":88,"@type":89},"Sarah ","Person",{"url":68,"name":91,"@type":92},"DocShare","Organization","application/pdf","2026-10-21","2026-10-13",true,{"@type":98,"interactionType":99,"userInteractionCount":47},"InteractionCounter",{"@type":100},"ViewAction",{"@type":102,"mainEntity":103},"FAQPage",[104,110,114],{"name":105,"@type":106,"acceptedAnswer":107},"How do you use an if/elif/else conditional in Bash?","Question",{"text":108,"@type":109},"Use if [[ condition1 ]]; then ... elif [[ condition2 ]]; then ... else ... fi. The corresponding command block runs based on which condition is true.","Answer",{"name":111,"@type":106,"acceptedAnswer":112},"What are common Bash file test operators like -f, -d, -z, and -n?",{"text":113,"@type":109},"-f checks that a file exists, -d checks that a directory exists, -z checks whether a string is empty, and -n checks whether a string is non-empty.",{"name":115,"@type":106,"acceptedAnswer":116},"How do you iterate using for loops and while loops in this cheat sheet?",{"text":117,"@type":109},"The for loop examples show iterating over lists and ranges, and looping over associative array indices. The while loop runs until the condition becomes false, using a numeric comparison inside (( ... )).","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},571886,1792431293,{"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":47,"is_deleted":4,"is_public":9,"is_downloadable":9,"audit_status":9,"page_count":73,"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":9},962085320529,"https://ap-avatar.wpscdn.com/davatar_9964176cb1d06d4a9deccf72a44ae3dc","BASH cheat sheet-Level 3  \nControl Structure  \nConditional statements  \nA) The if statement:  \nif [[ condition1 ]];then / !\\ The spaces are  \ncommand1  important in that syntax  \nelif [[ condition2 ]];then  \ncommand2  \nelse  \ncommand3  \nfi  \nPerform command1 if condition1 is true, elseif the condition2 is true the command2 is performed, else it’s the command3 that will be performed.  \nFile tests:  \n-­‐f file  True if file file exists  \n-­‐d dir  True if dir dir exists  \n-­‐z string  True if string is empty.  \n-­‐n string  True if string is non-­‐empty.  \nfile1 –nt file2  \nTrue if file1 has been changed more recently than file2, or if file1 exists and file2 does not.  \nfile1 –ot file2  \nTrue if file1 is older than file2, or if file2 exits and file1 does not.  \nString comparison operators:  \nstring1 == string2 Compare strings equality.  \nstring1 != string2 Compare strings inequality.  \nArithmetic comparison operators:  \nGenerally numeric comparisons on double square brackets are obsolete, however you may still used -­‐ eq, -­‐ ne, -­‐lt, -­‐le, -­‐gt, or -­‐ge, meaning equal, not equal, less than, less than or equal, greater than, and greater than or equal, respectively.  \n/ !\\ For arithmetic values it’s highly recommended to use the syntax (( condition )) . In that case, the  \nfollowing operators must be used : == , !=, \u003C , \u003C=,  \n> >=  \n,  \nPattern matching operator:  \nstring =~ regularExpression  \nTrue if string match the pattern of the regular expresion.  \nLogical operators :  \nif ! [[ condition ]]  \n! -­‐ NOT -­‐ Negate the truth. Evaluate as true only if condition is false.  \nif [[ condition1 ]] && [[ condition2 ]]  \n&& -­‐ AND – Check if both conditions are true.  \nif [[ condition1 ]] || [[ condition2 ]]  \n|| -­‐ OR – Check if one of the conditions is true.  \nB) The case statement:  \ncase $variable in  \npattern1)  \ncommands1  \n;;  \npattern2|pattern3|pattern4)  \ncommands2  \n;;  \npatternN)  \ncommands3  \n;;  \n*)  \ncommands4  \n;;  \nesac  \nIt allows to check a value multiple times. If the $variable match the pattern1, the commands1 are executed. If it matches none of them, the commands4 are executed.  \nThe loops  \nA) The for loop:  \nfor i in element1 element2 element3 ; do  \ncommand  \ndone  \nRepeat the command by assigning list’s elements to the variable i. The list can be implicit (e.g *.txt that iterates over all the txt files.)  \nfor (( i=1 ; i\u003C=10 ; i++ )) ; do  \ncommand  \ndone  \nThis is a C-­‐style for loop that iterates over the integers (here from 1 to 10 namely 10 times) .  \nfor i in {1..10}; do  \ncommand  \ndone  \nThis syntax allows to iterate a selected number of time (here from 1 to 10 namely 10 times) .  \nfor i in ${!array[@]} ; do  \necho \"key :\" $i  \necho \"value:\" ${array[$i]}  \ndone  \nIterate over an associative array.  \nB) The while loop:  \nThe while loop continue until the condition is false.  \ni=0  \nwhile (( $i \u003C= 10 )); do  \ncommand  \n((i++))  \ndone  \nIterate until $i is superior to 10, namely 10 times.  \nJacques Dainat -­‐ 2015  \nFile reading  \nfor line in $(cat file.txt); do  \ncommand  \ndone  \nRead the file file line by line and execute the command. / !\\ Here the line is defined by the IFS variable (see section’s end) . Set it to '\\n'to obtain the behavior expected.  \nwhile read line ;do Read the file file  \ncommand line by line and  \ndone \u003C file execute the command.  \nIFS=$'\\n' Set the Internal Field Separator (IFS)  \nvariable to '\\n'. By default its value is ' \\t\\n'(space, tab and newline) .  \nArrays and Hashes  \nA) Indexed array :  \narray=() or declare –a array  \nDeclare an indexed array and initialize it tobe empty. In the second case an existing array is not initialized.  \narray=(Anna Par Ulla)  \nThe array array is initialized with three values.  \narray[N]=value  \nSet the element N of the array array to value  \narray+=(value1 value2 value3)  \nAppend the array with three values.  \n${array[N]}  \nExpand the element referenced by the index N from array.  \n${\\#array[N]}  \nSize (string length) of the value ref","cbCaia8D4e9Kt4d5","https://ap.wps.com/l/cbCaia8D4e9Kt4d5","pdf",127155,"English","# Control Structure\n## Conditional statements\n## File tests\n## String comparison and arithmetic operators\n## Pattern matching and logical operators\n## Case statement\n## Loops\n## File reading\n## Arrays and Hashes\n## Programming in bash\n## Arguments and Functions\n## User interface","[{\"question\":\"How do you use an if/elif/else conditional in Bash?\",\"answer\":\"Use if [[ condition1 ]]; then ... elif [[ condition2 ]]; then ... else ... fi. The corresponding command block runs based on which condition is true.\"},{\"question\":\"What are common Bash file test operators like -f, -d, -z, and -n?\",\"answer\":\"-f checks that a file exists, -d checks that a directory exists, -z checks whether a string is empty, and -n checks whether a string is non-empty.\"},{\"question\":\"How do you iterate using for loops and while loops in this cheat sheet?\",\"answer\":\"The for loop examples show iterating over lists and ranges, and looping over associative array indices. The while loop runs until the condition becomes false, using a numeric comparison inside (( ... )).\"}]","BASH cheat sheet-Level 3 - Control Structure | PDF",1791924229]