[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-1-en-105":3,"doc-seo-571888-105":53,"doc-detail-571888-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-commands-cheat-sheet-running-a-bash-script-shebang-and-parameter-expansion","Bash commands cheat sheet - Running a Bash script - shebang and parameter expansion","","Bash commands cheat sheet covering how and why to run Bash scripts, including direct execution via bash \u003Cscript> and making scripts standalone with chmod +x. Explains the shebang header (#!) and how /usr/bin/bash versus /usr/env bash affects interpreter discovery through $PATH. Extends to executing scripts written in other languages using the proper shebang (e.g., Perl). Includes Bash variable declaration rules and parameter expansion techniques for uppercase/lowercase conversion, search-and-replace, regex character replacement, substring extraction, and case conversion.",{"@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":51,"@type":70,"position":76},"https://docshare.wps.com/template/general/",3,{"item":78,"name":59,"@type":70,"position":79},"https://docshare.wps.com/template/bash-commands-cheat-sheet-running-a-bash-script-shebang-and-parameter-expansion/571888/",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-commands-cheat-sheet-running-a-bash-script-shebang-and-parameter-expansion/571888.png","ImageObject",442,249,{"name":88,"@type":89},"นรินทร์","Person",{"url":68,"name":91,"@type":92},"DocShare","Organization","application/pdf","2026-10-25","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 a Bash script be run directly using the bash executable?","Question",{"text":109,"@type":110},"Call it as an argument to bash, such as: $ bash myscript Hello from Bash. The script file content runs as defined inside the file.","Answer",{"name":112,"@type":107,"acceptedAnswer":113},"What is the purpose of the shebang header (#!) in a Bash script?",{"text":114,"@type":110},"The shebang declares which interpreter the operating system should use to execute the script’s lines. It can point directly to /usr/bin/bash or use /usr/env bash to search via $PATH.",{"name":116,"@type":107,"acceptedAnswer":117},"How does Bash parameter expansion convert case and replace parts of strings?",{"text":118,"@type":110},"Case conversion uses forms like ${MSG^^} for uppercase and ${MSG,,} for lowercase. String replacement can use patterns such as ${MSG//Chris/Billy}, and regex-style character replacement can use ${MSG//[a-zA-Z]/X}.","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},571888,1792086998,{"code":4,"msg":5,"data":128},{"doc_id":125,"user_id":129,"nickname":88,"user_avatar":130,"doc_module":9,"category_id":50,"category_name":51,"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":40,"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":141},2336475104957,"https://ap-avatar.wpscdn.com/avatar/22000c4c6bd8a5076e1?x-image-process=image/resize,m_fixed,w_180,h_180&k=1787554080175789136","[developers.redhat.com](developers.redhat.com)  \n redhat-developer  \n @rhdevelopers  \nCheat sheet  \nBash commands  \nA Bash script is a text file that contains programming statements that execute commands that are part of the host computer’s operating system. Typically system administrators and programmers use Bash scripts to avoid having to repetitively execute tasks manually in a terminal.  \nA typical use case for a Bash script is to do set up tasks for a newly provisioned computer. Thus, in addition to being a tool for system administrators and programmers, a Bash script can also be used by system provisioning software.(The $ symbol that proceeds commands in the examples represents the command line prompt. )  \n Running a Bash script  \nThere are two ways to run a Bash script. The first way is to execute it as a parameter of a direct call to the bash  executable binary, like so:  \n$ bash myscript Hello from Bash  \nWHERE the content of the file myscript is as follows:  \necho \"Hello from Bash\"  \nThe second way to use the chmod command to change the permissions of the bash script to make it a standalone executable, like so:  \n$ chmod +x ./myscript  \n$ ./myscript  \n Using a shebang header  \nUnlike a binary executable file which knows how to interact with the computer’s operating system directly, a Bash script, which is always text based, requires another program to run its commands. This other program is called an interpreter. The interpreter that runs a Bash script is, as the name implies, bash . However, in other cases, a bash script can be run by another interpreter that’s installed on the host computer. An example of another interpreter is sh .  \nThe way a Bash script lets the operating system know which interpreter to use is according to a declaration made atthe first line of the script. This first line declaration is called a script header. It is also called a shebang. A shebang starts with the characters \\#!   \nAn example of a shebang is as follows:  \n[developers.redhat.com](developers.redhat.com)  \n redhat-developer  \n @rhdevelopers  \n\\#!/usr/bin/bash  \nThe shebang shown above tells the operating system to use the interpreter located at the filepath /usr/bin/bash to execute the lines of code that will follow in the script.  \nAnother form of a shebang is as follows:  \n\\#!/usr/env bash  \nThe shebang \\#!/usr/env bash tells the operating system to search the computer’s $PATH  to find the bash  interpreter. Thus, any instance of bash can be used as long as the it’s in a location defined by the $PATH environment variable.  \nExecuting scripts in another language  \nAs mentioned above, a host operating system has to have the capability to run scripts for other interpreted programming languages as long as the given interpreter is installed on the host computer and the shebang has been configured properly.  \nThe example below shows a Perl script file. Notice that the script header (a. k.a. shebang) declares the file as a Perl script:  \n\\#!/usr/bin/perl use strict;  \nuse warnings;  \nprint \"Hello World from Perl\\n\";  \nVariables  \nUsing variables is a critical factor for programming Bash scripts. The following sections describe various aspects of working with variables under Bash.  \nVariable declaration  \nYou declare a variable in a bash script like so  VARIABLE_NAME=\u003Cvalue>  WHERE  \u003Cvalue> is the value assigned to the variable. Then, to reference the variable, put the $ symbol before the variable name being referenced, like so:  \n$VARIABLE_NAME .  \nExample:  \n\\#!/usr/bin/env bash MSG=\"Hello World\"  \necho \"$MSG \" \\# Hello World  \n[developers.redhat.com](developers.redhat.com)  \n redhat-developer  \n @rhdevelopers  \nBE CAREFUL to make sure there is no space on either side of the = symbol when declaring a variable. The following will not work: MYVARIABLE = foo .  \nString manipulation using parameter expansion  \nParameter expansion a technique to get the value from the referenced entity such as a variable in a Linux script or an environment","cbCaijUHwiVNAuz5","https://ap.wps.com/l/cbCaijUHwiVNAuz5","pdf",280805,"English","# Running a Bash script\n## Execute with bash\n## Make it executable with chmod\n## Using a shebang header\n# Executing scripts in another language\n# Variables in Bash\n## Variable declaration\n## String manipulation with parameter expansion\n## Word replacement and character replacement\n## Extracting substrings\n## Case conversion","[{\"question\":\"How can a Bash script be run directly using the bash executable?\",\"answer\":\"Call it as an argument to bash, such as: $ bash myscript Hello from Bash. The script file content runs as defined inside the file.\"},{\"question\":\"What is the purpose of the shebang header (#!) in a Bash script?\",\"answer\":\"The shebang declares which interpreter the operating system should use to execute the script’s lines. It can point directly to /usr/bin/bash or use /usr/env bash to search via $PATH.\"},{\"question\":\"How does Bash parameter expansion convert case and replace parts of strings?\",\"answer\":\"Case conversion uses forms like ${MSG^^} for uppercase and ${MSG,,} for lowercase. String replacement can use patterns such as ${MSG//Chris/Billy}, and regex-style character replacement can use ${MSG//[a-zA-Z]/X}.\"}]","Bash commands cheat sheet - Running a Bash script - shebang and parameter expansion | PDF",1791924245,6]