Jump to: | OMake Home • Guide Home • Guide (single-page) • Contents (short) • Contents (long) | |
Index: | All • Variables • Functions • Objects • Targets • Options |
Shell commands (commands to be executed by the operating system) can be freely mixed with other code.
NOTE: the syntax and shell usage is identical on all platforms, including Win32. To avoid
portability problems on Win32, it is recommended that you avoid the use of the native shell
interpreter cmd
.
LIB = $(dir lib) println(The contents of the $(LIB) directory is:) ls $(LIB)
The syntax of shell commands is similar to the syntax used by the Unix shell bash
. In
general, a command is a pipeline. A basic command is part of a pipeline. It is specified
with the name of an executable and some arguments. Here are some examples.
ls ls -AF . echo Hello world
The command is found using the current search path in the variable PATH[]
, which should
define an array of directories containing executables.
A command may also be prefixed by environment variable definitions.
# Prints "Hello world" env X="Hello world" Y=2 printenv X # Pass the include path to the Visual C++ env include="c:\Program Files\Microsoft SDK\include" cl foo.cpp
Commands may contain wildcard patterns. A pattern specifies a set of files through a limited kind of regular expression. Patterns are expanded before the function is executed.
# List all files with a .c suffix ls *.c # List all files with a single character prefix, and .c suffix ls ?.c # Rename the file hello.ml to foo.ml mv {hello,foo}.ml
A comprehensive description of OMake glob patterns is given in Section 11.4.
The command may also be placed in the background by placing an ampersand after the command. Control returns to the shell without waiting for the job to complete. The job continues to run in the background.
gcc -o hugeprogram *.c &
Input and output can be redirected to files by using the <
, >
, and >&
directives after the command.
# Write to the "foo" file echo Hello world > foo # Redirect input from the foo file cat < foo # Redirect standard output and errors to the foo file gcc -o boo *.c >& foo
Pipelines are sequences of commands, where the output from each command is sent to the next.
Pipelines are defined with the |
and |&
syntax. With |
the output is
redirected, but errors are not. With |&
both output and errors are redirected.
# Send the output of the ls command to the printer ls *.c | lpr # Send output and errors to jyh as email gcc -o hugefile *.c |& mail jyh
Commands may also be composed though conditional evaluation using the ||
and &&
syntax. Every command has an integer exit code, which may be zero or some other integer. A command
is said to succeed if its exit code is zero. The expression command1 && command2
executes command2
only if command1
succeeds. The expression
command1 || command2
executes command2
only if command1
fails.
# Display the x/y file if possible cd x && cat y # Run foo.exe, or print an error message (test -x foo.exe && foo.exe) || echo "foo.exe is not executable"
Parenthesis are used for grouping in a pipeline or conditional command. In the following
expression, the test
function is used to test whether the foo.exe
file is executable.
If it is, the foo.exe
file is executed. If the file is not executable (or if the
foo.exe
command fails), the message "foo.exe is not executable"
is printed.
# Run foo.exe, or print an error message (test -x foo.exe && foo.exe) || echo "foo.exe is not executable"
Syntactially, shell commands are any line that is not one of the following:
VAR=string
f(...)
or method call o.f(...)
string: ...
if ...
switch ...
match ...
section ...
return ...
Commands may also be builtin (aliases). See the documentation for the
Shell
object for more information.
The echo
function prints a string.
$(echo <args>) echo <args>
The cd
function changes the current directory.
cd(dir) dir : Dir
The cd
function also supports a 2-argument form:
$(cd dir, e) dir : Dir e : expression
In the two-argument form, expression e
is evaluated
in the directory dir
. The current directory is not
changed otherwise.
The behavior of the cd
function can be changed with the
CDPATH
variable, which specifies a search path for
directories. This is normally useful only in the osh
command interpreter.
CDPATH : Dir Sequence
For example, the following will change directory to the first
directory ./foo
, ~/dir1/foo
, ~/dir2/foo
.
CDPATH[] = . $(HOME)/dir1 $(HOME)/dir2 cd foo
The jobs
function prints a list of jobs.
jobs
The bg
function places a job in the background.
bg <pid...>
The fg
function brings a job to the foreground.
fg <pid...>
The stop
function suspends a job.
stop <pid...>
The wait
function waits for a job to finish.
If no process identifiers are given, the shell waits for
all jobs to complete.
wait <pid...>
The kill
function signals a job.
kill [signal] <pid...>
$(history-index) : Int $(history) : String Sequence history-file : File history-length : Int
The history variables manage the command-line history in osh. They have no effect in omake.
The history-index
variable is the current index into the command-line history.
The history
variable is the current command-line history.
The history-file
variable can be redefined if you want the command-line history
to be saved. The default value is ~/.omake/osh_history
.
The history-length
variable can be redefined to specify the maximum number of
lines in the history that you want saved. The default value is 100
.
Jump to: | OMake Home • Guide Home • Guide (single-page) • Contents (short) • Contents (long) | |
Index: | All • Variables • Functions • Objects • Targets • Options |