|
This part of the guide contains detailed descriptions of the
BUSH built-in packages.
4.9 command_line Package
The command_line package provides communication between a script and the
calling program. This package sets the exit status and processes command
line option switches. command_line contains following routines:
GCC Ada equivalent: Ada.Command_Line
n := command_line.argument_count
return the number of script arguments (the same as $#). Exclude BUSH
option switches.
Example: if command_line.argument_count > 0 then ...
Ada Equivalent: Ada.Command_Line.Argument_Count
Parameters:
n |
return value |
natural |
required |
the argument count |
|
s := command_line.argument( p )
return a command line argument (the same as $n where n is a number).
The arguments do not include option swithes interpreted by BUSH.
Example: put_line( "First argument is " & command_line.argument(
1 ) );
Ada Equivalent: Ada.Command_Line.Argument
Parameters:
p |
in |
positive |
required |
the argument number |
s |
return value |
string |
required |
the value of the argument |
|
A bad argument number will raise an exception.
s := command_line.command_name
return the the name of the script or BUSH interpreter (the same as
$0)
Example: put_line( command_line.command_name & " is this script"
);
Ada Equivalent: Ada.Command_Line.Command_Name
Parameters:
s |
return value |
string |
required |
the name of the script or BUSH interpreter |
|
n := command_line.environment.environment_count
return the number of variables in the operating system environment.
Example: for i in 1..command_line.environment.environment_count loop
...
Ada Equivalent: Ada.Command_Line.Environment.Environment_Count
Parameters:
n |
return value |
natural |
required |
the argument count |
|
s := command_line.environment.environment_value( p )
return an operating system environment value in the form of "VAR=value".
Example: put_line( "First value is " & command_line.environment.environment_value(
1 ) );
Ada Equivalent: Ada.Command_Line.Environment.Environment_Value
Parameters:
p |
in |
positive |
required |
the argument number |
s |
return value |
string |
required |
the value of the argument |
|
A bad environment value number will raise an exception.
command_line.set_exit_status( n )
set the status code to be returned by the script to the calling program.
(To read the exit status, use os.status.)
Example: command_line.set_exit_status( 0 ); -- all is well
Ada Equivalent: Ada.Command_Line.Set_Exit_Status
Parameters:
i |
in |
short_short_integer |
required |
the status code to return (0 for no error) |
|
End of Document
Back to Top
|