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

Bourne Shell Word Expansions

SparForte provides a subset of Bourne shell features for convenient use on the command line.  Many new users are already familiar with the Bourne shell since it's the standard shell for Linux and FreeBSD.  Also, the AdaScript syntax can be awkward to use for simple interactive commands.  Where the Bourne standard conflicts with Ada SparForte always favors compatibility with Ada for the sake of the progressive development model.

Bourne shell arguments consist of groups of characters called "words".  Each word is separated by spaces.  SparForte does not implement the Bourne shell IFS variable.

Argument expansion is the process of performing substitutions on a Bourne shell word.  Argument expansion occurs at run-time since it depends on the current working directory and the current value of variables.

Shell Expansion Coverage

Bourne shell expansions include:


Expansion
Before
After
SparForte
Brace Expansion
a.{txt,.dat}
a.txt a.dat
not implemented
Tilde Expansion
~a/a.txt
/home/user/a.txt
OK
Variable Expansion
$HOME/a.txt
/home/usr/a.txt
OK
Command Substitution
`/bin/echo a.txt`
a.txt
Backquotes only
Arithmetic Expansion
$((2+2))
4
not implemented
(use AdaScript parameters)
Pathname Expansion
a.*
a.txt a.dat
OK
Word Splitting
a\ word
"a word"
OK

There is no brace expansion, arithmetic expansion or process substitution.  Some features support only a subset of the BASH features.  For example, many of the special $ substitutions (${...}, $(...) and others) are not implemented.  Otherwise, the basic Bourne shell features implemented in SparForte conform to the POSIX standard.

Spaces and Dollar Expansions

Variable expansions are affected by quotation and the data type of expansion variable. If no quotes are used, the leading and trailing spaces are discarded. If in single quotes, no variable expansion occurs at all. If double quotes are used, the affect on spaces depends on the data type. If the value is numeric, the leading space for a positive variable is discarded (to mimic shell behaviour) but other variable types maintain any leading or trailing spaces.

To prevent unexpected word splitting, most dollar variable expansions are expected to be quoted. This excludes the special variables $?, $#, and $$ and on the command line. This check can be disabled with pragma suppress( word_quoting ).

=> s : string := " hello "
=> put_line( s )
hello
=> echo $s
hello
=> echo "$s"
 hello 
=> echo '$s'
$s
=> echo `pwd;`"$s"
/home/ken/ada/SparForte/src hello 
=> t : string
=> t := `echo $s;`
=> env t
t := "hello"; -- identifier of the type string
=> t := `echo "$s";`
=> env t
t := " hello "; -- identifier of the type string
=> i : integer := 5
=> put_line( i )
 5
=> echo $i
5
=> echo "$i"
5
 

Example: The leading/trailing space is affected by quotations and variable type

 
[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]