{"id":19727,"date":"2025-09-09T12:23:20","date_gmt":"2025-09-09T11:23:20","guid":{"rendered":"https:\/\/digitalrezaid.com\/oldrezaid\/?p=19727"},"modified":"2025-09-16T07:03:42","modified_gmt":"2025-09-16T06:03:42","slug":"how-to-run-a-bash-script","status":"publish","type":"post","link":"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script","title":{"rendered":"How to run a bash script\u200b"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"19727\" class=\"elementor elementor-19727\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-78fc042 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"78fc042\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-51d2fe5\" data-id=\"51d2fe5\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-3fcf738 elementor-widget elementor-widget-image\" data-id=\"3fcf738\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"1000\" height=\"562\" src=\"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/How-to-run-a-bash-script.webp\" class=\"attachment-large size-large wp-image-19759\" alt=\"How to run a bash script\" srcset=\"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/How-to-run-a-bash-script.webp 1000w, https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/How-to-run-a-bash-script-300x169.webp 300w, https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/How-to-run-a-bash-script-768x432.webp 768w, https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/How-to-run-a-bash-script-600x337.webp 600w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ee79749 elementor-widget elementor-widget-text-editor\" data-id=\"ee79749\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><span style=\"font-weight: 400;\">With software development, system administration and even recreational computing, the capability to automate repetitive processes is the superpower. The secret of this power on Linux, macOS and even on Windows (using WSL or Git Bash) is frequently the simple Bash script. A script written using the Bash language is just a plain text file consisting of a series of commands which may be executed by the Bash shell. But when you are at the command line and new to it you do not always know how to run that script. This guide will take you through the different methods and why they work and prepare you to execute any script that you come across. Learn more about <a href=\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/manual-testing-vs-automated-testing-which-is-best\">automated testing<\/a> and how scripting fits into modern QA processes.<\/span><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8d8a86c elementor-widget elementor-widget-heading\" data-id=\"8d8a86c\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Requirements: To test a simple script to write.\n<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-06d648f elementor-widget elementor-widget-image\" data-id=\"06d648f\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"1024\" height=\"559\" src=\"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/Requirements-To-test-a-simple-script-to-write.webp\" class=\"attachment-large size-large wp-image-19762\" alt=\"Requirements To test a simple script to write\" srcset=\"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/Requirements-To-test-a-simple-script-to-write.webp 1024w, https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/Requirements-To-test-a-simple-script-to-write-300x164.webp 300w, https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/Requirements-To-test-a-simple-script-to-write-768x419.webp 768w, https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/Requirements-To-test-a-simple-script-to-write-600x328.webp 600w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-547c14b elementor-widget elementor-widget-text-editor\" data-id=\"547c14b\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><span style=\"font-weight: 400;\">You have to have one before you can run a script. To demonstrate, we&#8217;ll write a simple and harmless script. Open a terminal and open a text editor such as nano:<\/span><\/p><p>\u00a0<\/p><p><span style=\"font-weight: 400;\">bash<\/span><\/p><p><span style=\"font-weight: 400;\">nano hello_world.sh<\/span><\/p><p><span style=\"font-weight: 400;\">These lines are to be typed in the editor. The opening line is unique and vital, as we will see in the future.<\/span><\/p><p>\u00a0<\/p><p><span style=\"font-weight: 400;\">bash<\/span><\/p><p><span style=\"font-weight: 400;\">#!\/bin\/bash<\/span><\/p><p><span style=\"font-weight: 400;\"># This is a comment. It won&#8217;t be executed.<\/span><\/p><p><span style=\"font-weight: 400;\">echo &#8220;Hello, World!&#8221;<\/span><\/p><p><span style=\"font-weight: 400;\">echo: time and date are: $(date).<\/span><\/p><p><span style=\"font-weight: 400;\">Write and quit the editor (in nano, Ctrl+X, then Y for yes, then Enter).<\/span><\/p><p>\u00a0<\/p><p><span style=\"font-weight: 400;\">Congratulations! The script file is now created: hello world.sh. But when you attempt to run it right away, typing its name, you are likely to get an error:<\/span><\/p><p>\u00a0<\/p><p><span style=\"font-weight: 400;\">Bash<\/span><\/p><p><span style=\"font-weight: 400;\">$ hello_world.sh<\/span><\/p><p><span style=\"font-weight: 400;\">Hello, world.sh: command not found.<\/span><\/p><p><span style=\"font-weight: 400;\">This is the initial big obstacle for newcomers. The system does not simply run any file that you type. You must inform them of how to perform it. Let us consider the right methods.<\/span><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2a4a218 elementor-widget elementor-widget-heading\" data-id=\"2a4a218\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Method 1: How to make the Script executable (The Standard Way)<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4e0021e elementor-widget elementor-widget-image\" data-id=\"4e0021e\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"1024\" height=\"559\" src=\"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/How-to-make-the-Script-executable.webp\" class=\"attachment-large size-large wp-image-19761\" alt=\"How to make the Script executable\" srcset=\"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/How-to-make-the-Script-executable.webp 1024w, https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/How-to-make-the-Script-executable-300x164.webp 300w, https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/How-to-make-the-Script-executable-768x419.webp 768w, https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/How-to-make-the-Script-executable-600x328.webp 600w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-77e10da elementor-widget elementor-widget-text-editor\" data-id=\"77e10da\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><span style=\"font-weight: 400;\">This is the most appropriate and standard way of executing scripts that you intend to use on a regular basis. It involves two steps.<\/span><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ce02ade elementor-widget elementor-widget-heading\" data-id=\"ce02ade\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Step 1: Select the Execute Permission.\n<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-70e72b9 elementor-widget elementor-widget-text-editor\" data-id=\"70e72b9\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><span style=\"font-weight: 400;\">Unix-like systems feature files with permissions that allow specifying who is allowed to read write to or execute a file. The default permission of a new text file is not the execute (x) permission. We give it with the change mode (chmod) command.<\/span><\/p><p><span style=\"font-weight: 400;\">bash<\/span><\/p><p><span style=\"font-weight: 400;\">chmod +x hello_world.sh<\/span><\/p><p><span style=\"font-weight: 400;\">chmod: The command.<\/span><\/p><p><span style=\"font-weight: 400;\">+x: Add execute permission to the user and group and also to others (a shorthand of a+x).<\/span><\/p><p><span style=\"font-weight: 400;\">Hello world.sh: The target file.<\/span><\/p><p><span style=\"font-weight: 400;\">The permissions also could be checked by running ls -l. You can view the x in the permission string (e.g. -rwxr-xr-x). <\/span>Explore some essential <a href=\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/top-8-automation-testing-tools-any-self-respecting-tester-must-use\">automation tools<\/a> for testers and developers.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a7d1988 elementor-widget elementor-widget-heading\" data-id=\"a7d1988\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Step 2: Execute the Script<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9f09936 elementor-widget elementor-widget-text-editor\" data-id=\"9f09936\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><span style=\"font-weight: 400;\">At this point the file is ready to run. But security reasons keep the shell in your current directory and unless it is explicitly instructed to the contrary, it does not search there. You have two options:<\/span><\/p><p><b>Option A: Specify the Path (.\/)<\/b><\/p><p><span style=\"font-weight: 400;\">The safest and the advisable method is to give the route to the script. The\/ is an abbreviation of in the current directory.<\/span><\/p><p><span style=\"font-weight: 400;\">bash<\/span><\/p><p><span style=\"font-weight: 400;\">.\/hello_world.sh<\/span><\/p><p><span style=\"font-weight: 400;\">Output:<\/span><\/p><p><span style=\"font-weight: 400;\">text<\/span><\/p><p><span style=\"font-weight: 400;\">Hello, World!<\/span><\/p><p><span style=\"font-weight: 400;\">The system date and time are: Sun Sep 8 10:30:00 UTC 2024.<\/span><\/p><p><strong>Option B: relocate to a Script Directory on your $PATH.<\/strong><\/p><p><span style=\"font-weight: 400;\">To have your script run like any other command, e.g. by simply typing hello-world.sh, anywhere, you can move it to a directory in the system PATH, e.g., \/usr\/local\/bin\/.<\/span><\/p><p><span style=\"font-weight: 400;\">bash<\/span><\/p><p><span style=\"font-weight: 400;\">mv that script (must use sudo with system directories).<\/span><\/p><p><span style=\"font-weight: 400;\">Sudo mv hello world.sh to \/usr\/local\/bin\/<\/span><\/p><p><span style=\"font-weight: 400;\">Now it can be executed out of any directory.<\/span><\/p><p><span style=\"font-weight: 400;\">hello_world.sh<\/span><\/p><p><span style=\"font-weight: 400;\">This is ideal with well-tried scripts used on a system-wide basis. See how scripting supports <a href=\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/the-role-of-python-developers-in-streamlining-software-engineering-processes\">developer workflows<\/a> across languages like Python and Bash.<\/span><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-cdb8932 elementor-widget elementor-widget-heading\" data-id=\"cdb8932\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Method 2: Get the Script (The \".\" or \"source\" Command)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-96fb09a elementor-widget elementor-widget-text-editor\" data-id=\"96fb09a\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><span style=\"font-weight: 400;\">There are times when you do not wish the script to execute a new shell process. Rather you need it to operate in your existing shell. It is accomplished through sourcing the script.<\/span><\/p><p><span style=\"font-weight: 400;\">The source command can be used, or the dot (.) operator (equivalent):<\/span><\/p><p><span style=\"font-weight: 400;\">bash<\/span><\/p><p><span style=\"font-weight: 400;\">Both these commands are identical.<\/span><\/p><p><span style=\"font-weight: 400;\">source hello_world.sh<\/span><\/p><p><span style=\"font-weight: 400;\">.\/hello_world.sh<\/span><\/p><p><span style=\"font-weight: 400;\">Why would you do this?<\/span><\/p><p><span style=\"font-weight: 400;\">The major dissimilarity lies in the way variables and changes in the environment are processed.<\/span><\/p><p><b>Normal execution (.\/script sh):<\/b><span style=\"font-weight: 400;\"> The script executes in a subshell. Any variables it establishes or any directory changes (cd) it makes are lost after the script has been executed. They are not taken into your current terminal session.<\/span><\/p><p><b>Sourcing (source script.sh): <\/b><span style=\"font-weight: 400;\">The commands in the script are run like the commands typed in your current shell. Any changes it makes persist.<\/span><\/p><p><b>Example Use Case: <\/b><span style=\"font-weight: 400;\">You have a script that initializes a number of environment variables to a development project. You would like such variables to appear on your terminal once the script is run. configure_environment.sh would be sourced.<\/span><\/p><p>For real-world examples, see how <a href=\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-use-sicm-software\">data automation<\/a> works inside specialized software tools.<\/p><p><b>Caution:<\/b><span style=\"font-weight: 400;\"> You should not execute any other script without first verifying the authorship of the author since this source would permanently modify your shell environment.<\/span><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-bd47271 elementor-widget elementor-widget-heading\" data-id=\"bd47271\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Method 3: bash invocation.\n<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0c62967 elementor-widget elementor-widget-text-editor\" data-id=\"0c62967\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><span style=\"font-weight: 400;\">You can even avoid the requirement of the execute permission at all by simply using the script as an argument to the bash command itself.<\/span><\/p><p><span style=\"font-weight: 400;\">bash<\/span><\/p><p><span style=\"font-weight: 400;\">bash hello_world.sh<\/span><\/p><p><span style=\"font-weight: 400;\">By so doing, you are directly launching a new Bash shell and telling it to read and run the contents of hello_world.sh. This #!\/bin\/bash line (so-called shebang) within the script is excluded since you have already stated what interpreter to use.<\/span><\/p><p><span style=\"font-weight: 400;\">It is an excellent way of:<\/span><\/p><p><span style=\"font-weight: 400;\">Test a script very quickly without having to muck around with chmod.<\/span><\/p><p><span style=\"font-weight: 400;\">Execution of a script compiled to run on another shell (e.g. one may execute sh script.sh to run it on the simpler sh interpreter).<\/span><\/p><p><span style=\"font-weight: 400;\">You can add flags such as -x to make all the calls visible as they are run: debugging.<\/span><\/p><p>\u00a0<\/p><p><span style=\"font-weight: 400;\">bash<\/span><\/p><p><span style=\"font-weight: 400;\">bash -x hello_world.sh<\/span><\/p><p><span style=\"font-weight: 400;\">Output:<\/span><\/p><p>\u00a0<\/p><p><span style=\"font-weight: 400;\">text<\/span><\/p><p><span style=\"font-weight: 400;\">+ echo &#8216;Hello, World!&#8217;<\/span><\/p><p><span style=\"font-weight: 400;\">Hello, World!<\/span><\/p><p><span style=\"font-weight: 400;\">+ date<\/span><\/p><p><span style=\"font-weight: 400;\">+ date September 8, 2024, 10:30:00<\/span><\/p><p><span style=\"font-weight: 400;\">+ time Sun Sep 8 10:30:00 UTC 2024<\/span><\/p><p><span style=\"font-weight: 400;\">The time and date are: Sun Sep 8 10:30:00 UTC 2024.<\/span><\/p><p><span style=\"font-weight: 400;\">The shebang (#!\/bin\/bash)<\/span><\/p><p><span style=\"font-weight: 400;\">Our initial line of script, #!\/bin\/bash is known as a shebang (or hashbang). It is magic that makes Methods 1 and 2 work.<\/span><\/p><p><span style=\"font-weight: 400;\">When you just run a file (e.g., .\/myscript), the operating system takes a look at this first line to determine what program is to be used to interpret the file. The #! informs the OS that this is a script and the path \/bin\/bash is the absolute path to the interpreter in this case being the Bash shell.<\/span><\/p><p><span style=\"font-weight: 400;\">This is so potent in that what is written in any interpreted language can be run without problems:<\/span><\/p><p><span style=\"font-weight: 400;\">For Python: #!\/usr\/bin\/env python3<\/span><\/p><p><span style=\"font-weight: 400;\">For Perl: #!\/usr\/bin\/perl<\/span><\/p><p><span style=\"font-weight: 400;\">For Node.js: #!\/usr\/bin\/env node<\/span><\/p><p>\u00a0<\/p><p><span style=\"font-weight: 400;\">A typical workaround is to use the trick \/usr\/bin\/env in order to execute the env command to identify the interpreter in the user&#8217;s path, which makes the script more portable.<\/span><\/p><p><span style=\"font-weight: 400;\">When the shebang is absent and one tries to run the script directly, the system will normally attempt to run the script in your present shell. This may be fine with simple Bash scripts, but it is not very reliable and is bad practice. Always include a shebang.<\/span><\/p><p><span style=\"font-weight: 400;\">It is possible to troubleshoot Common Permission Errors.<\/span><\/p><p><b>Access denied: <\/b><span style=\"font-weight: 400;\">You have not executed chmod +x script.sh. Use this or execute it with a bash script.sh.<\/span><\/p><p>\u00a0<\/p><p><b>Unknown command:<\/b><span style=\"font-weight: 400;\"> You have typed the name of the script but have not given the path. In the same directory use .\/script sh.<\/span><\/p><p><br \/><b>No file or directory of this type:<\/b><span style=\"font-weight: 400;\"> You are probably in the discarded files directory. To list files, use ls and to identify where you are, use pwd and then change to the right directory using the command cd. Furthermore, verify the typos in the name.<\/span><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3adc88c elementor-widget elementor-widget-heading\" data-id=\"3adc88c\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Conclusion\n<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e17b58d elementor-widget elementor-widget-text-editor\" data-id=\"e17b58d\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><span style=\"font-weight: 400;\">Ancillary skills such as running a Bash script open oopenthe gate to amazing efficiency. To recap: The regular method: chmod +x script.sh and <\/span><a href=\"http:\/\/script.sh\"><span style=\"font-weight: 400;\">script.sh<\/span><\/a><span style=\"font-weight: 400;\">. To make current shell changes: source script.sh or <\/span><span style=\"font-weight: 400;\">source.script.sh<\/span><span style=\"font-weight: 400;\">. To debug or to quickly test: bash script.sh or bash -x <\/span><a href=\"http:\/\/script.sh\"><span style=\"font-weight: 400;\">script.sh<\/span><\/a><span style=\"font-weight: 400;\"> Also bear in mind the strength of the shebang (#!\/bin\/bash) in order to make your scripts self-contained and portable. These are just some of the easy ways to start and automate simple tasks, and with practice you can use the complete power of the command line to have your computer do the work.<\/span><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-84703ae elementor-widget elementor-widget-heading\" data-id=\"84703ae\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">FAQs<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c760108 elementor-widget elementor-widget-text-editor\" data-id=\"c760108\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3><b>1. How do I run a Bash script?<\/b><\/h3><p><span style=\"font-weight: 400;\">Make it executable and run the script.sh, or execute the bash script.sh.<\/span><\/p><p>\u00a0<\/p><h3><b>2. Why do I need chmod +x?<\/b><\/h3><p><span style=\"font-weight: 400;\">It authorizes the file to execute as a program.<\/span><\/p><p>\u00a0<\/p><h3><b>3. What does &#8220;.\/&#8221; mean?<\/b><\/h3><p><span style=\"font-weight: 400;\">It directs the shell to search the script in the present folder.<\/span><\/p><p>\u00a0<\/p><h3><b>4. What is #!\/bin\/bash?<\/b><\/h3><p><span style=\"font-weight: 400;\">It\u2019s a shebang, which instructs the system to use Bash to execute the script.<\/span><\/p><p>\u00a0<\/p><h3><b>5. What is the difference between .\/script sh and source script.sh?<\/b><\/h3><p><span style=\"font-weight: 400;\">.\/ opens a new shell and the source uses the current shell.<\/span><\/p><p>\u00a0<\/p><h3><b>6. Is it possible to execute Bash scripts under Windows?<\/b><\/h3><p><span style=\"font-weight: 400;\">Yes, in WSL, Git Bash, or Cygwin.<\/span><\/p><p>\u00a0<\/p><h3><b>7. Why do I get \u201ccommand not found\u201d?<\/b><\/h3><p><span style=\"font-weight: 400;\">You have either forgotten .\/ or are not there.<\/span><\/p><p>\u00a0<\/p><h3><b>8. How do I debug a script?<\/b><\/h3><p><span style=\"font-weight: 400;\">Bash -x script.sh to view each command as it is being run.<\/span><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>With software development, system administration and even recreational computing, the capability to automate repetitive processes is the superpower. The secret of this power on Linux, macOS and even on Windows<a href=\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script\" rel=\"bookmark\"><span class=\"screen-reader-text\">How to run a bash script\u200b<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":19747,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"off","neve_meta_content_width":70,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[693],"tags":[],"class_list":["post-19727","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guides"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to run a bash script\u200b - Rezaid<\/title>\n<meta name=\"description\" content=\"Learn how to write, make executable, and properly run a Bash script\u2014from shebang to permissions\u2014for fast, reliable automation in Unix\/Linux.\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to run a bash script\u200b - Rezaid\" \/>\n<meta property=\"og:description\" content=\"Learn how to write, make executable, and properly run a Bash script\u2014from shebang to permissions\u2014for fast, reliable automation in Unix\/Linux.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script\" \/>\n<meta property=\"og:site_name\" content=\"Rezaid\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/rezaidglobaluk\" \/>\n<meta property=\"article:published_time\" content=\"2025-09-09T11:23:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-16T06:03:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/how-to-run-bas-scrip.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1500\" \/>\n\t<meta property=\"og:image:height\" content=\"450\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"umerrezaid@gmail.com\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Rezaid_mcr\" \/>\n<meta name=\"twitter:site\" content=\"@Rezaid_mcr\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"umerrezaid@gmail.com\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script#article\",\"isPartOf\":{\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script\"},\"author\":{\"name\":\"umerrezaid@gmail.com\",\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/#\/schema\/person\/1f00b0a1beb7c782945a5d8bb7dd1bea\"},\"headline\":\"How to run a bash script\u200b\",\"datePublished\":\"2025-09-09T11:23:20+00:00\",\"dateModified\":\"2025-09-16T06:03:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script\"},\"wordCount\":1578,\"publisher\":{\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/#organization\"},\"image\":{\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script#primaryimage\"},\"thumbnailUrl\":\"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/how-to-run-bas-scrip.jpg\",\"articleSection\":[\"guides\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script\",\"url\":\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script\",\"name\":\"How to run a bash script\u200b - Rezaid\",\"isPartOf\":{\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script#primaryimage\"},\"image\":{\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script#primaryimage\"},\"thumbnailUrl\":\"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/how-to-run-bas-scrip.jpg\",\"datePublished\":\"2025-09-09T11:23:20+00:00\",\"dateModified\":\"2025-09-16T06:03:42+00:00\",\"description\":\"Learn how to write, make executable, and properly run a Bash script\u2014from shebang to permissions\u2014for fast, reliable automation in Unix\/Linux.\",\"breadcrumb\":{\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script#primaryimage\",\"url\":\"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/how-to-run-bas-scrip.jpg\",\"contentUrl\":\"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/how-to-run-bas-scrip.jpg\",\"width\":1500,\"height\":450,\"caption\":\"how to run bash scrip\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/digitalrezaid.com\/oldrezaid\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to run a bash script\u200b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/#website\",\"url\":\"https:\/\/digitalrezaid.com\/oldrezaid\/\",\"name\":\"Rezaid\",\"description\":\"Digital Marketing &amp; Web Development Agency UK\",\"publisher\":{\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/digitalrezaid.com\/oldrezaid\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/#organization\",\"name\":\"Rezaid\",\"url\":\"https:\/\/digitalrezaid.com\/oldrezaid\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/05\/logo-rezaid.webp\",\"contentUrl\":\"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/05\/logo-rezaid.webp\",\"width\":441,\"height\":89,\"caption\":\"Rezaid\"},\"image\":{\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/rezaidglobaluk\",\"https:\/\/x.com\/Rezaid_mcr\",\"https:\/\/www.linkedin.com\/company\/rezaid-global\",\"https:\/\/www.instagram.com\/rezaid.global\/\",\"https:\/\/uk.pinterest.com\/rezaidglobal\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/#\/schema\/person\/1f00b0a1beb7c782945a5d8bb7dd1bea\",\"name\":\"umerrezaid@gmail.com\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/digitalrezaid.com\/oldrezaid\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/dd5bdc5cbbc7a64d7fc4f55f9bacd436c7cdab798068eae53fff2a6e80a5fabf?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/dd5bdc5cbbc7a64d7fc4f55f9bacd436c7cdab798068eae53fff2a6e80a5fabf?s=96&d=mm&r=g\",\"caption\":\"umerrezaid@gmail.com\"},\"url\":\"https:\/\/digitalrezaid.com\/oldrezaid\/post\/author\/umerrezaidgmail-com\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to run a bash script\u200b - Rezaid","description":"Learn how to write, make executable, and properly run a Bash script\u2014from shebang to permissions\u2014for fast, reliable automation in Unix\/Linux.","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"How to run a bash script\u200b - Rezaid","og_description":"Learn how to write, make executable, and properly run a Bash script\u2014from shebang to permissions\u2014for fast, reliable automation in Unix\/Linux.","og_url":"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script","og_site_name":"Rezaid","article_publisher":"https:\/\/www.facebook.com\/rezaidglobaluk","article_published_time":"2025-09-09T11:23:20+00:00","article_modified_time":"2025-09-16T06:03:42+00:00","og_image":[{"width":1500,"height":450,"url":"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/how-to-run-bas-scrip.jpg","type":"image\/jpeg"}],"author":"umerrezaid@gmail.com","twitter_card":"summary_large_image","twitter_creator":"@Rezaid_mcr","twitter_site":"@Rezaid_mcr","twitter_misc":{"Written by":"umerrezaid@gmail.com","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script#article","isPartOf":{"@id":"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script"},"author":{"name":"umerrezaid@gmail.com","@id":"https:\/\/digitalrezaid.com\/oldrezaid\/#\/schema\/person\/1f00b0a1beb7c782945a5d8bb7dd1bea"},"headline":"How to run a bash script\u200b","datePublished":"2025-09-09T11:23:20+00:00","dateModified":"2025-09-16T06:03:42+00:00","mainEntityOfPage":{"@id":"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script"},"wordCount":1578,"publisher":{"@id":"https:\/\/digitalrezaid.com\/oldrezaid\/#organization"},"image":{"@id":"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script#primaryimage"},"thumbnailUrl":"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/how-to-run-bas-scrip.jpg","articleSection":["guides"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script","url":"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script","name":"How to run a bash script\u200b - Rezaid","isPartOf":{"@id":"https:\/\/digitalrezaid.com\/oldrezaid\/#website"},"primaryImageOfPage":{"@id":"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script#primaryimage"},"image":{"@id":"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script#primaryimage"},"thumbnailUrl":"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/how-to-run-bas-scrip.jpg","datePublished":"2025-09-09T11:23:20+00:00","dateModified":"2025-09-16T06:03:42+00:00","description":"Learn how to write, make executable, and properly run a Bash script\u2014from shebang to permissions\u2014for fast, reliable automation in Unix\/Linux.","breadcrumb":{"@id":"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script#primaryimage","url":"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/how-to-run-bas-scrip.jpg","contentUrl":"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/09\/how-to-run-bas-scrip.jpg","width":1500,"height":450,"caption":"how to run bash scrip"},{"@type":"BreadcrumbList","@id":"https:\/\/digitalrezaid.com\/oldrezaid\/post\/how-to-run-a-bash-script#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/digitalrezaid.com\/oldrezaid\/"},{"@type":"ListItem","position":2,"name":"How to run a bash script\u200b"}]},{"@type":"WebSite","@id":"https:\/\/digitalrezaid.com\/oldrezaid\/#website","url":"https:\/\/digitalrezaid.com\/oldrezaid\/","name":"Rezaid","description":"Digital Marketing &amp; Web Development Agency UK","publisher":{"@id":"https:\/\/digitalrezaid.com\/oldrezaid\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/digitalrezaid.com\/oldrezaid\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/digitalrezaid.com\/oldrezaid\/#organization","name":"Rezaid","url":"https:\/\/digitalrezaid.com\/oldrezaid\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/digitalrezaid.com\/oldrezaid\/#\/schema\/logo\/image\/","url":"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/05\/logo-rezaid.webp","contentUrl":"https:\/\/digitalrezaid.com\/oldrezaid\/wp-content\/uploads\/2025\/05\/logo-rezaid.webp","width":441,"height":89,"caption":"Rezaid"},"image":{"@id":"https:\/\/digitalrezaid.com\/oldrezaid\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/rezaidglobaluk","https:\/\/x.com\/Rezaid_mcr","https:\/\/www.linkedin.com\/company\/rezaid-global","https:\/\/www.instagram.com\/rezaid.global\/","https:\/\/uk.pinterest.com\/rezaidglobal\/"]},{"@type":"Person","@id":"https:\/\/digitalrezaid.com\/oldrezaid\/#\/schema\/person\/1f00b0a1beb7c782945a5d8bb7dd1bea","name":"umerrezaid@gmail.com","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/digitalrezaid.com\/oldrezaid\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/dd5bdc5cbbc7a64d7fc4f55f9bacd436c7cdab798068eae53fff2a6e80a5fabf?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dd5bdc5cbbc7a64d7fc4f55f9bacd436c7cdab798068eae53fff2a6e80a5fabf?s=96&d=mm&r=g","caption":"umerrezaid@gmail.com"},"url":"https:\/\/digitalrezaid.com\/oldrezaid\/post\/author\/umerrezaidgmail-com"}]}},"_links":{"self":[{"href":"https:\/\/digitalrezaid.com\/oldrezaid\/wp-json\/wp\/v2\/posts\/19727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digitalrezaid.com\/oldrezaid\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digitalrezaid.com\/oldrezaid\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digitalrezaid.com\/oldrezaid\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/digitalrezaid.com\/oldrezaid\/wp-json\/wp\/v2\/comments?post=19727"}],"version-history":[{"count":21,"href":"https:\/\/digitalrezaid.com\/oldrezaid\/wp-json\/wp\/v2\/posts\/19727\/revisions"}],"predecessor-version":[{"id":20272,"href":"https:\/\/digitalrezaid.com\/oldrezaid\/wp-json\/wp\/v2\/posts\/19727\/revisions\/20272"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digitalrezaid.com\/oldrezaid\/wp-json\/wp\/v2\/media\/19747"}],"wp:attachment":[{"href":"https:\/\/digitalrezaid.com\/oldrezaid\/wp-json\/wp\/v2\/media?parent=19727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digitalrezaid.com\/oldrezaid\/wp-json\/wp\/v2\/categories?post=19727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digitalrezaid.com\/oldrezaid\/wp-json\/wp\/v2\/tags?post=19727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}