I have a program called
perl shuffle.pl Input Shuffled
.tools/shuffle.pl: 5: Syntax error: "(" unexpected
set path = (. ~ ~/.tools /sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin )
use List::Util qw(first max maxstr min minstr reduce shuffle sum);
my @Lines = readline($fh);
my @Shuffled = shuffle(@Lines);
print $shuf @Shuffled;
The shebang is used to tell which interpreter should be used for this script. For this to work, the magic number
#! has to appear at the immediate beginning of the file. Otherwise, the default interpreter is used.
In this case, the shebang was preceded by a few empty lines. They have to be removed.
The shebang is not parsed when an explicit interpreter is used to execute the file, E.g. in
$ perl script.pl.
It is only important when launched as executable:
./script.pl. In that case, the kernel is left to figure out what to do with it: Load into memory as compiled program? Launch an interpreter? Which one? Magic numbers like
#! resolve this.
In general, if the shebang doesn't work, the following possible errors can be checked:
FE FFat the beginning.
#!when opened as ASCII or does not begin with
23 21in a hexdump. Or your editor shows UTF-16 or UTF-32 as the encoding.
Non-native line endings can be confused to be part of the executable name. E.g. with windows line endings, the shebang in
#!/usr/bin/perl print 1;
could be taken as the interpreter name
"/usr/bin/perl\r". Many filesystems allow line endings inside filenames.
Diagnosis: A hexdump shows something other than a space (
20) or newline (
0A) after the executable name.
Solution: Convert line endings to Unix.