When we write shell scripts we do this:
#!/bin/bash
But What if bash is in /usr/bin/
? How can we find it in a portable way inside script? I did this, but it gives error:
#!which bash
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityWhen we write shell scripts we do this:
#!/bin/bash
But What if bash is in /usr/bin/
? How can we find it in a portable way inside script? I did this, but it gives error:
#!which bash
If bash
is in the different location you can hash bang it as follows:
#!/usr/bin/env bash
Location for env
is pretty standard across the variants.
#!/usr/bin/env python
Feb 19, 2012 at 19:43
bash
as /bin/bash
(via a symlink if necessary) simply because so many scripts out there have #!/bin/bash
.
Feb 19, 2012 at 21:59
#!/bin/bash
doesn't necessarily make them right.