03-31-2007
Part 2 -- The Details
The Format of the #! Line
We can say for certain that the first 2 characters must be "#!". Or can we? Many systems, it seems, are willing to delete leading white space. My recommendation is to start with #!. It's traditional.
Next there may be an optional space. Some documentation says this space is required but as far as anyone can determine the only Unix release to require the space was a snapshot release of BSD 4.1... this was not a general release). Actually, it appears that you may have several spaces if you want. And some testing with TAB characters has been done and seems to work. My recommendation is to stay with zero or one spaces.
Next comes the full path to the interpreter and like all full paths, it must start with a /. Oops, another exception... The Linux kernel (at least version 2.0.34) is willing to accept a relative path. My recommendation is don't do that.
We may be done. Or we may have optional white space which lead to our single argument. Except that some versions of FreeBSD handle multiple arguments.
Most versions of BSD and HP-UX will strip trailing white space. Other versions of Unix treat trailing white space as valid characters. And a few versions of BSD can accept a trailing comment delimited by a # character.
How long can the line be? A few versions of Unix set the limit as low as 32 characters. FreeBSD can apparently handle 8192 characters.
At least the line always ends with the Unix standard \n character, right? Well, not always. Some versions of Unix will tolerate a \r\n ending and strip off the \r while others won't do that.
This is not as standard as it could be...
Argument 0 of The Process, Not The Script
There is another way that implementations may differ. Consider the perl script that I ran ar the end of part 1. My shell did the approximate equivalent of
execl("./perlargs", "./perlargs", "one", "two", "three", (char *) NULL)
and the kernel transformed it into the approximate equivalent of
execl("/usr/local/bin/perl", "/usr/local/bin/perl", "-w", "./perlargs", "one", "two", "three", (char *) NULL)
Highlighted in red is argument zero which by convention is the same as the path of the program being executed. A notable execution is that the login program will set it to stuff like "-ksh". Originally, executable shell scripts had the argument 0 set to the name of the script rather than the name of the interpreter. These days, the name of the interpreter is common. The last hold-out I know of is HP-UX which sets argument 0 to the name of the script.
These 3 Users Gave Thanks to Perderabo For This Post:
8 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I have a developer that is trying to start a script with sh "scriptname". In the script, he is specifying #!/usr/bin/ksh as the command interpreter. For some reason sh is ignoring the #!/usr/bin/ksh. We are running Solaris 8. Does anyone have any ideas what could be causing this? Here... (3 Replies)
Discussion started by: ckeith79
3 Replies
2. UNIX for Dummies Questions & Answers
I am using IBM AIX unix version 4.3.3.0.
In a directory there are many files with different patterns.
When I am trying to execute the command, ls -l with the file pattern, which have fewer files it gives the desired result. However when I am trying to execute the same command for file pattern,... (2 Replies)
Discussion started by: jitindrabappa
2 Replies
3. Solaris
Hi all,
below is the problem details:
ora10g@CNORACLE1>which ld
/usr/ucb/ld
ora10g@CNORACLE1>cd /usr/ccs/bin
ora10g@CNORACLE1>ln -s /usr/ucb/ld ld
ln: cannot create ld: File exists
ora10g@CNORACLE1>
how to link it to /usr/ccs/bin? (6 Replies)
Discussion started by: SmartAntz
6 Replies
4. Shell Programming and Scripting
Usually we use !/usr/bin/ksh at the start of the script.But if I am having this stuff in the scripts and calling one script from other its not working.What may be the reason behind it ?
xyz.ksh
#!/usr/bin/ksh
echo "Hi"
abc.ksh
#!/usr/bin/ksh
echo "I am fine"
ksh xyz.ksh
Its... (4 Replies)
Discussion started by: dr46014
4 Replies
5. AIX
Hi,
I am getting the below error message When i am trying to delete the files from the directory.Could you please guide me?
rm *.aud
ksh: /usr/bin/rm: 0403-027 The parameter list is too long.
and
find /oracle/admin/testP/adump/*.aud -mtime +5 -exec rm {} \;
ksh: /usr/bin/find:... (3 Replies)
Discussion started by: nokiae63
3 Replies
6. OS X (Apple)
Q1. I understand that /usr/local/bin means I can install/uninstall stuff in here and have any chance of messing up my original system files or effecting any other users. I created this directory myself.
But what about the directory I didn't create, namely /Users/m/bin? How is that directory... (1 Reply)
Discussion started by: michellepace
1 Replies
7. Shell Programming and Scripting
I saw one script using the first line as below
/usr/bin/ksh -E
I have used -x for debug but couldn't find what is this -E option for ?
Pls let me know what is this -E used for
Thanks
RL (1 Reply)
Discussion started by: reldb
1 Replies
8. BSD
I'm not sure if this is the default behavior for the ld command, but it does not seem to be looking in /usr/local/lib for shared libraries.
I was trying to compile the latest version of Kanatest from svn. The autorgen.sh script seems to exit without too much trouble:
$ ./autogen.sh
checking... (2 Replies)
Discussion started by: AntumDeluge
2 Replies
LEARN ABOUT CENTOS
tap::parser::sourcehandler::perl
TAP::Parser::SourceHandler::Perl(3) User Contributed Perl Documentation TAP::Parser::SourceHandler::Perl(3)
NAME
TAP::Parser::SourceHandler::Perl - Stream TAP from a Perl executable
VERSION
Version 3.28
SYNOPSIS
use TAP::Parser::Source;
use TAP::Parser::SourceHandler::Perl;
my $source = TAP::Parser::Source->new->raw( 'script.pl' );
$source->assemble_meta;
my $class = 'TAP::Parser::SourceHandler::Perl';
my $vote = $class->can_handle( $source );
my $iter = $class->make_iterator( $source );
DESCRIPTION
This is a Perl TAP::Parser::SourceHandler - it has 2 jobs:
1. Figure out if the TAP::Parser::Source it's given is actually a Perl script ("can_handle").
2. Creates an iterator for Perl sources ("make_iterator").
Unless you're writing a plugin or subclassing TAP::Parser, you probably won't need to use this module directly.
METHODS
Class Methods
"can_handle"
my $vote = $class->can_handle( $source );
Only votes if $source looks like a file. Casts the following votes:
0.9 if it has a shebang ala "#!...perl"
0.75 if it has any shebang
0.8 if it's a .t file
0.9 if it's a .pl file
0.75 if it's in a 't' directory
0.25 by default (backwards compat)
"make_iterator"
my $iterator = $class->make_iterator( $source );
Constructs & returns a new TAP::Parser::Iterator::Process for the source. Assumes "$source->raw" contains a reference to the perl script.
"croak"s if the file could not be found.
The command to run is built as follows:
$perl @switches $perl_script @test_args
The perl command to use is determined by "get_perl". The command generated is guaranteed to preserve:
PERL5LIB
PERL5OPT
Taint Mode, if set in the script's shebang
Note: the command generated will not respect any shebang line defined in your Perl script. This is only a problem if you have compiled a
custom version of Perl or if you want to use a specific version of Perl for one test and a different version for another, for example:
#!/path/to/a/custom_perl --some --args
#!/usr/local/perl-5.6/bin/perl -w
Currently you need to write a plugin to get around this.
"get_taint"
Decode any taint switches from a Perl shebang line.
# $taint will be 't'
my $taint = TAP::Parser::SourceHandler::Perl->get_taint( '#!/usr/bin/perl -t' );
# $untaint will be undefined
my $untaint = TAP::Parser::SourceHandler::Perl->get_taint( '#!/usr/bin/perl' );
"get_perl"
Gets the version of Perl currently running the test suite.
SUBCLASSING
Please see "SUBCLASSING" in TAP::Parser for a subclassing overview.
Example
package MyPerlSourceHandler;
use strict;
use vars '@ISA';
use TAP::Parser::SourceHandler::Perl;
@ISA = qw( TAP::Parser::SourceHandler::Perl );
# use the version of perl from the shebang line in the test file
sub get_perl {
my $self = shift;
if (my $shebang = $self->shebang( $self->{file} )) {
$shebang =~ /^#!(.*perl.*?)(?:(?:s)|(?:$))/;
return $1 if $1;
}
return $self->SUPER::get_perl(@_);
}
SEE ALSO
TAP::Object, TAP::Parser, TAP::Parser::IteratorFactory, TAP::Parser::SourceHandler, TAP::Parser::SourceHandler::Executable,
TAP::Parser::SourceHandler::File, TAP::Parser::SourceHandler::Handle, TAP::Parser::SourceHandler::RawTAP
perl v5.16.3 2013-05-02 TAP::Parser::SourceHandler::Perl(3)