LOGBOOK

HELP

Quiz Entry - updated: 2026.06.20

How do you make a shell script executable and run it?

Two steps: chmod +x script.sh to grant execute permission, then ./script.sh to run it from the current directory.

A fresh script is just a text file — Linux won't run it until the execute bit is set, which is what chmod +x does. Then you launch it with ./script.sh. The ./ matters: the shell only auto-searches directories in $PATH, and your current directory normally isn't one of them (a deliberate security choice — otherwise a malicious ls dropped in a folder could hijack the real command). ./ says "the file is right here."

1. Make executable:

chmod +x myscript.sh

2. Run the script:

./myscript.sh              # From current directory
/home/user/myscript.sh     # Full path
bash myscript.sh           # Without execute permission

Why ./ is needed:

  • Current directory is usually NOT in PATH
  • ./ explicitly means "current directory"

Alternative - add to PATH:

# Add script directory to PATH
export PATH="$PATH:$HOME/bin"
# Now you can run without path
myscript.sh

Tip: Store personal scripts in ~/bin and add it to your PATH.

From Quiz: LIOS / Bash Scripting and Automation | Updated: Jun 20, 2026