I am looking for someone to authoritatively confirm or correct what I think I know about the -CSDA
option on the shebang line of a Perl script.
See perldoc perlrun for the documentation of -CSDA
. Briefly
- S:
STDIN
,STDOUT
andSTDERR
are assumed to be in UTF-8- D: UTF-8 is the default PerlIO layer for both input and output streams
- A: @ARGV elements are expected to be strings encoded in UTF-8
For -CSDA
to have any effect, it must be specified on the command line as in perl -CSDA script.pl
.
Prior to 5.10, -CSDA
on the shebang line would silently fail because the standard streams would have already been opened and @ARGV
already populated by the time it was encountered unless -CSDA
was already specified on the command line as well.
After 5.10, -CSDA
which appears only on the shebang line causes perl
to croak because of that problem.
A script with -CSDA
that used to work with perl
s pre-5.10 should have the -CSDA
removed from the shebang line because it was never invoked with those options on the command line (and the options, if specified solely on the shebang line, did nothing).
I would love to get some solid feedback on which of my assumptions above are wrong.
The shebang is a special character sequence in a script file that specifies which program should be called to run the script. The shebang is always on the first line of the file, and is composed of the characters #! followed by the path to the interpreter program.
Rules for the shebang The shebang command must be the first line of the file and can contain any valid path for the interpreter, followed by an argument that the command will receive. The shebang line is read by the system before the execution of the program, but that line will not be automatically deleted.01-Dec-2014.
#!/usr/bin/env python """ The first line in this file is the "shebang" line. When you execute a file from the shell, the shell tries to run the file using the command specified on the shebang line. The ! is called the "bang". The # is not called the "she", so sometimes the "shebang" line is also called the "hashbang".
The shebang must be the first line because it is interpreted by the kernel, which looks at the two bytes at the start of an executable file. If these are #! the rest of the line is interpreted as the executable to run and with the script file available to that program.
Not sure how authoritative I am, but I know how this works.
If your script is
#!/usr/bin/perl -CSDA
and you start your script using
./script foo
The OS will launch Perl as follows:
/usr/bin/perl -CSDA ./script foo
The change in behaviour only comes into play if launch the script incorrectly, such as by using
/usr/bin/perl ./script foo
The fix isn't to remove -CSDA
, the fix is to call the script correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With