Begin every Bash script
This page was last updated on August 19, 2013.
- Make this the first line of every Bash script:
-
#!/bin/bash
- Or make this the first line of every Bash script when you’d like to avoid the default behavior of having Bash read /etc/profile (the system-wide startup file) or ~/.bash_profile, ~/.bash_login, or ~/.profile (any of the personal initialization files):
-
#!/bin/bash --noprofile
These are special comment lines that are not required, but are used by convention to let the shell (the environment the terminal is running in) know which interpreter to use when running your script.
Obligatory Happy Ending
And they all lived happily ever after. The end.

I would say something like this is better if you’re writing just a shell script:
#!/bin/bash –noprofile
You don’t need all the overhead of processing the startup scripts just to fork a process that already has a PATH, HOME, etc.
Comment by Jerry — April 3, 2010 @ 2:22 pm
Good point! I’m adding it now. :)
Comment by mostlylinux — April 3, 2010 @ 8:36 pm