<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									How do you make a Bash script executable - Operating System				            </title>
            <link>https://www.hacktheforum.com/operating-system/how-do-you-make-a-bash-script-executable/</link>
            <description>Hack The Forum Discussion Board</description>
            <language>en</language>
            <lastBuildDate>Sat, 18 Apr 2026 10:56:58 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>How do you make a Bash script executable</title>
                        <link>https://www.hacktheforum.com/operating-system/how-do-you-make-a-bash-script-executable/#post-817</link>
                        <pubDate>Fri, 29 Nov 2024 10:57:25 +0000</pubDate>
                        <description><![CDATA[Making a Bash script executable involves two main steps:

Create the script (if you haven&#039;t already).
Change the file&#039;s permissions to make it executable.

Step-by-Step Guide to Make a ...]]></description>
                        <content:encoded><![CDATA[<p>Making a Bash script executable involves two main steps:</p>
<ol>
<li><strong>Create the script</strong> (if you haven't already).</li>
<li><strong>Change the file's permissions</strong> to make it executable.</li>
</ol>
<h3>Step-by-Step Guide to Make a Bash Script Executable</h3>
<h4>1. <strong>Create the Bash Script</strong></h4>
<p>If you don't have a script yet, you can create one using any text editor. For example, let's create a simple script called <code>myscript.sh</code>.</p>
<p>Open a terminal and use a text editor to create the script file. Here's an example using <code>nano</code>:</p>
<div class="contain-inline-size rounded-md border- border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none">
<pre contenteditable="false">nano myscript.sh</pre>
</div>
</div>
<p>In the editor, write your script. For example:</p>
<div class="contain-inline-size rounded-md border- border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none">
<pre contenteditable="false">#!/bin/bash
echo "Hello, World!"
</pre>
</div>
</div>
<p>After writing your script, save the file. In <code>nano</code>, press <code>Ctrl + O</code> to save and <code>Ctrl + X</code> to exit the editor.</p>
<h4>2. <strong>Make the Script Executable</strong></h4>
<p>Now that you have a script file (<code>myscript.sh</code>), you need to change its permissions to make it executable.</p>
<p>Use the <code>chmod</code> command to do this:</p>
<div class="contain-inline-size rounded-md border- border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none">
<pre contenteditable="false">chmod +x myscript.sh
</pre>
</div>
</div>
<ul>
<li><code>chmod</code> is the command to change file permissions.</li>
<li><code>+x</code> adds the "execute" permission for the user, allowing the script to be run as a program.</li>
</ul>
<h4>3. <strong>Run the Script</strong></h4>
<p>Once you've made the script executable, you can run it.</p>
<p>If the script is in your current directory, use the <code>./</code> syntax to run it:</p>
<div class="contain-inline-size rounded-md border- border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none">
<pre contenteditable="false">./myscript.sh
</pre>
</div>
</div>
<p>This should output:</p>
<div class="contain-inline-size rounded-md border- border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none">
<pre contenteditable="false">Hello, World!
</pre>
</div>
</div>
<h3>Understanding <code>chmod +x</code></h3>
<ul>
<li><strong><code>chmod</code></strong>: The command to change file permissions.</li>
<li><strong><code>+x</code></strong>: This part adds the execute (<code>x</code>) permission. Without this, you can’t run the script as a program directly.</li>
<li><strong>Example with <code>chmod</code></strong>: If you run <code>chmod 755 myscript.sh</code>, it gives full permissions to the owner (read, write, execute), and read and execute permissions to the group and others.</li>
</ul>
<h4>Example Permissions:</h4>
<p>You can check the file permissions using <code>ls -l</code>:</p>
<div class="contain-inline-size rounded-md border- border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none">
<pre contenteditable="false">ls -l myscript.sh
</pre>
</div>
</div>
<p>Before you run <code>chmod +x</code>:</p>
<div class="contain-inline-size rounded-md border- border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none">
<pre contenteditable="false">-rw-r--r-- 1 user user 44 Nov 29 14:30 myscript.sh
</pre>
</div>
</div>
<p>After running <code>chmod +x</code>:</p>
<div class="contain-inline-size rounded-md border- border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none">
<pre contenteditable="false">-rwxr-xr-x 1 user user 44 Nov 29 14:30 myscript.sh
</pre>
</div>
</div>
<p>The key change is the addition of the <code>x</code> in the permissions (<code>rwx</code> for the owner, <code>r-x</code> for group and others).</p>
<h3>Notes:</h3>
<ul>
<li>
<p><strong>Shebang (<code>#!/bin/bash</code>)</strong>: It's a good practice to include the shebang (<code>#!/bin/bash</code>) at the top of your script. It tells the system that the script should be executed using the Bash shell, no matter what shell the user is currently in.</p>
</li>
<li>
<p><strong>Running Scripts in Other Directories</strong>: If your script is located in a different directory (not the current one), you can either specify the full path, or if you want to run it from anywhere, add its directory to the system's <code>PATH</code>.</p>
</li>
</ul>]]></content:encoded>
						                            <category domain="https://www.hacktheforum.com/operating-system/">Operating System</category>                        <dc:creator>paul0000</dc:creator>
                        <guid isPermaLink="true">https://www.hacktheforum.com/operating-system/how-do-you-make-a-bash-script-executable/#post-817</guid>
                    </item>
							        </channel>
        </rss>
		