7
#!/usr/bin/perl

This is the shebang line to a lot of scripts I'm writing lately.

Hard coding the path of the binary seems like it could create some problems. For instance, if one of my users has Perl installed at /something_else/bin then they'd have to change all the shebangs.

I've seen some tools that will automatically replace the shebangs, but I'm wondering if there is something simpler.

Mike
  • 58,961
  • 76
  • 175
  • 221

2 Answers2

16

env(1)

#!/usr/bin/env perl
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
1

For odd embedded systems where env is not in /usr/bin/env (E.g. NAS boxes running funplug etc) this might work. Based on the ActivePerl / DOS trick

#!/bin/sh
exec perl -x -S "$0" "$@"
#!perl
print "hello";
Community
  • 1
  • 1
ydrol
  • 139
  • 1
  • 3