[SparForte][Banner]
[Top Main Menu] Intro | Tutorials | Reference | Packages | Examples | Contributors   [Back Page]      [Next Page]  

External Commands

Running External Commands

The purpose of a shell script is, ultimately, to execute shell commands. Any command not understood by AdaScript as a command is assumed to be a shell command. For example,

=> echo

will run the Linux/UNIX echo command and print a blank line to the screen, the same as new_line in the text_io package.

Command Parameters

Commands are accepted in one of two different formats. If the command is followed by a "(", the parameters are expected to be in AdaScript format with each parameter separated by a comma (","). These parameters may be any legitimate AdaScript expression and no shell quote removal or file globbing is performed.

=> ls( "spar.adb" )
spar.adb

If the command is not followed by a "(", the parameters are expected to be in Bourne shell format. This is provided for convenience in interactive sessions.  The parameters are shell "words" separated by spaces. Each word has file globbing performed. The words may be enclosed in double quotes to allow embedded spaces, or single quotes to inhibit file globbing. Special characters may also be escaped with backslashes.

=> ls b*.adb
builtins.adb spar.adb

For information on reading Bourne shell arguments, see Command Argument Shortcuts.

Variable Expansion

SparForte can insert the values of variables using BASH-style "$" substitutions.  "ls $HOME" will show the contents of your home directory.

See this page for details on various expansions.

Quoting Commands

Command names containing space characters can be quoted with double quotes.

=> "inventory report"

When pragma ada_95 is used, shell commands must only use the AdaScript parameter format.

Running Commands in the Background

External commands can be run in the background using an ampersand ("&") at the end of the command. With AdaScript parameters, place the ampersand after the closing parenthesis. The jobs command displays the status of any outstanding background commands.

The built-in shell commands are listed in a section above. when a Linux command conflicts with a built-in command, the Linux command can be executed using the command command.

Capturing Command Output

The results of a command can be captured as a string using backquotes.  The commands should be ended with a semi-colon.  Commands appearing in backquotes will be syntax checked along with the rest of the commands in a script.

=> date : string := `date;`

If there is a trailing line feed (or carriage return/line feed for Windows) it will be removed.

Standard input, standard error and standard output can be redirected using the Text_IO package.


 
[Right Submenu]

 AdaScript versus GCC

 Case Sensitivity

 Reserved Words

 Comments

 Literals

 Bourne Shell Word Expansions

 Fundamental Types

 User-defined Types

 Enumerated Types

 Arrays

 Records

 Basic Assignment

 The @ and % Operands

 Command Argument Shortcuts

 Redirection and Pipelines

 Command Line Interaction

 Built-in Shell Commands

 The Current Directory

 Database Commands

 Flow of Control

 Other Statements/ Subprograms

 External Commands

 Block Statements and Subprograms

 TCP/IP Sockets

 Numeric Formatting with Put

 Interpreter Directives

 Command Line Options

 Command Reference

 ASCII and Latin_1 Character Sets

 Common Error Messages

 Common PHP Functions and the SparForte Equivalent

[Back to Top] Back To Top [Small Forte Symbol]