Operations 4 min read

Multiple Ways to Execute Shell Scripts and Manage Permissions

This article explains five methods to run a shell script—interpreter, relative and absolute path execution, dot sourcing, and the source command—demonstrates required permission settings, and provides a concise overview of Linux permission concepts and chmod usage for script execution.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Multiple Ways to Execute Shell Scripts and Manage Permissions

Shell scripts can be run using various techniques, each requiring appropriate execution permissions.

1. Interpreter execution – run the script by explicitly invoking the interpreter, e.g., /bin/bash script.sh .

2. Relative‑path execution – after granting execute permission, run the script from its directory:

chmod +x first.sh

./first.sh

Output: Hello World!

3. Absolute‑path execution – similarly grant permission and call the script with its full path:

chmod o+x first.sh

pwd (shows /root)

/root/first.sh

Output: Hello World!

4. Dot‑source execution – source the script in the current shell:

. first.sh

Output: Hello World!

5. Using the source builtin – equivalent to dot‑source:

source first.sh

Output: Hello World!

In production environments, it is generally recommended to execute scripts without adding extra permissions.

Extended content – interpreter list – the file /etc/shells lists available shells such as /bin/sh, /bin/bash, /sbin/nologin, /usr/bin/sh, /usr/bin/bash, /bin/tcsh, /bin/csh.

Linux permission basics – the ll (or ls -l ) command shows file mode bits; for example, -rw-r--r-- means read/write for owner, read for group and others. Permission bits are r (read), w (write), x (execute).

Changing permissions with chmod – syntax: chmod [u,g,o] [+-=] [rwx] file . Examples:

chmod u+x first.sh → -rwxr--r--

chmod u-x first.sh → -rw-r--r--

chmod +x first.sh → -rwxr-xr-x

LinuxshellexecutionPermissionsscriptchmod
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.