How to make a Bash script executable and run it from anywhere on the system¶
Follow these steps to make a Bash script executable and runnable from anywhere using a simple custom command like update.
1. Create Your Script¶
Write your Bash script and save it with a .sh extension (e.g., update.sh):
2. Make the Script Executable¶
Grant execution permissions to the script:
3. Move the Script to a Directory in PATH¶
Place the script in a directory included in your system's PATH (such as /usr/local/bin or /usr/bin) to make it globally accessible:
Now you can run the script from any terminal directory simply by typing update.
4. Verify Your PATH (Optional)¶
If /usr/local/bin is not already in your PATH, add it by editing your shell configuration file (~/.bashrc, ~/.zshrc, etc.):
Reload the configuration file to apply changes:
5. Test the Command¶
Run your new custom command: