For your scripts/programs, instead of:
#!/usr/bin/python
#!/usr/bin/perl
#!/usr/bin/ruby
#!/bin/bash
use env instead. How?
#!/usr/bin/env perl
#!/usr/bin/env python
#!/usr/bin/env ruby
#!/usr/bin/env bash
It finds the executable for you, in your path.
Because almost every system (except apparently certain versions of Unicos and Openserver) has the env program in /usr/bin/, but the perl or python or ruby or bash executable is more often found in a different directory than /usr/bin/.
I've seen them in:
/usr/local/bin
/opt/local/bin
/usr/pkg/bin
...etc. They could be installed anywhere actually. Perhaps even your home directory. /usr/bin/env solves this portability problem when you try to run a script on a machine with different location for perl/python/ruby/bash etc.
No it isn't. Look in /usr/bin/ too - I'll bet you find it. If you really don't, then you are using a pretty strange system (perhaps Unicos or something) - in which you might have many greater portability problems than this.
Yeah there could be. Let's say you have multiple versions of perl installed on your system - 5.8 and 5.6, where the main perl in your path points to 5.8. You could have a script that purposely needs to use 5.6 instead of 5.8 because of certain compatibility problems. In this case you might want to use #!/full/path/to/perl5.6 not #!/usr/bin/env.
Django Python 960.gs Git Vim NetBSD Nginx
This is the blog of Brad Willis, a software engineer living in Brisbane.
Help
Latest entries
*BSD Agile Apache Apple apt Athletics Best-Practice Censorship Chrome Comedy Cool Crosswords Deployment Django English Exim Firefox Git Hardcore Health irssi Javascript Jira Languages Linux Makefile Mathematics Mobile Broadband Mutt MySQL NetBSD nginx Nokia OpenVZ OSX Perl Postfix Privacy Python Rant Requirements rsync Ruby Shell Slackware SQL SQLite SSH Standards Subversion Television Testing ThisBlog Vim VMWare (Fusion) VPN X zsh
gvim - Always open new files as new tabs
crontab - escape % (percentage)
OSX Google Chrome - start in incognito mode
SQLite date arithmetic
Postfix - delete message in mailq
Checking for exceptions in doctests
Homer's Curling Speech
retry in Python
Vim Makefile tabs
Centos (or RH) IPTables
Converting ssh2 public keys to openssh
Vim comment hints
Context managers in Perl
Dish rotation
Git - fixing commit user
apt stuff
Using shell variables in AWK
Linux - Too many open files
Tell gvim to save and quit... remotely
Vim - automatically remove whitespace at EOL
Python - relative paths from within modules
TV Aspect Ratios
Git - Which commits are in your branch only?
Subversion setup cheat sheet
Force detach a screen session
Modify sudo's use of environment variables
Install all Perl modules
Mutt - delete old messages
OpenVZ VPS and swap space
fail2ban on NetBSD for ssh
NetBSD - Using sup
Python - testing for a sys.exit
Python Best Practice Link Dump
Python script names
Perl - Using an expensive module
Speed of git clone
Perl Modules with Custom Prefix
Perl: tr vs. s
Brilliant sysadmin Reference
Why is GRUB better than LILO?