[Previous] [Contents] [Index] [Next]

Caution: This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.

esh

Embedded shell (QNX Neutrino)

Syntax:

esh [-c command] [-irv] [script_file]

Options:

-c command
Run this command.
-i
Enter interactive mode after running a script file. If you don't specify this option, esh terminates after running a script.
-r
Run in restricted mode. In this mode, you can't perform certain operations. If you try to, the error message, "Operation not permitted" is displayed.

Restricted operations include running executables that start with a slash, exporting variables, and reattaching standard input, output and error to another device. For more information, see the sections "Command-line format" and "Builtin commands."

-v
Be verbose: echo each command before executing it.
script_file
A file containing shell commands to execute.

Description:

The esh utility provides a subset of the functionality found in the standard shell, /bin/sh. You should find esh useful for situations where memory requirements are limited. For example, you could use it to run a simple system initialization file for an embedded system.

Command-line format

In esh, command lines take this form:

command arg1 arg2 ... [redir-op file] [&]

Where:

command
The command to be executed. If it doesn't start with a slash, the command follows the path set by the PATH environment variable. In restricted mode, a command can't start with a slash.
redir-op file
A redirection operator. When a command is invoked, three standard files are set up in its environment. These files, standard input, standard output, and standard error output (stdin, stdout, stderr), are usually attached to the active terminal. You can redirect a command's standard input, standard output, and standard error as follows:
Specifying:  Will:
<file Redirect standard input from this file.
>file Redirect standard output to this file. If the file exists, it's overwritten; if the file doesn't exist, it's created.
>>file Redirect standard output to this file. If the file exists, the information is appended to the end of the file; if the file doesn't exist, it's created.
2>file Do the same as >file, but for standard error.
2>>file Do the same as >>file, but for standard error.
& If a command contains an unquoted &, then esh doesn't wait for the command to complete execution but immediately moves on to process the next command. The standard input of the command is redirected from /dev/null, and SIGINT and SIGQUIT are ignored.

Filename expansion

You use most commands for manipulating files in one way or another. As such, esh has a filename "shorthand" (consisting of *, ?, [, and ]) that you can use to specify the files that a command is to operate on. This shorthand is the same used by the standard shell. For more information, see "Filename patterns" in ksh.

Quoting

The following characters have a special meaning in esh:

&  \  "  *  ?  [  space

To suppress the special meaning of these characters and keep their literal meaning, you use quoting.

To quote a sequence of characters or sequence of words, enclose the sequence in double quotes. To quote a single character, use double quotes or precede it with the escape character (\).

Escape character (backslash)

The escape character (\) preserves the literal meaning of the next character. You can't obtain a single backslash by quoting \ with double quotes. To obtain a backslash, enter \\ instead.

Double quotes

Enclosing characters and words in double quotes ("") preserves the literal meaning of all characters within double quotes, with the exception of the \ character. For example:

"ab cd"

represents a single, five-character argument.

You can keep the literal meaning of a double quote with the \ character. For example:

ab\"cd

represents the single, five-character argument ab"cd.

Builtin commands

The following commands are built into esh (that is, esh interprets and executes them internally):

. (dot) command

. file

The . (dot) command reads and executes the commands from file within the current environment. The search path contained in the environment variable PATH is used to find the directory containing file. This command doesn't require that file be executable.

alias command

alias [name=value]...

Without arguments, alias lists all aliases and their values. If only the name is specified, its value is listed. Any name specified with a value defines an alias.

Alias expansion occurs when the first word of a statement is a defined alias, except when that alias is already being expanded.

List all aliases:

alias

Remove an alias:

alias name=

cd command

cd [directory]

Change the working directory of the current execution environment. If directory isn't specified, the value of the HOME environment variable becomes the new working directory.

emount command

emount special directory [fs_type]

Mount a special device. The arguments are:

special
The name of the special device.
mountpoint
Where to mount the device on your system.
type
The type of filesystem or manager to mount:
type: Filesystem or manager:
cd fs-cd.so
cifs fs-cifs
dos fs-dos.so
ext2 fs-ext2.so
nfs fs-nfs2, fs-nfs3
qnx4 fs-qnx4.so

The default is qnx4.


Note: The emount command was implemented in QNX Momentics 6.3.0 Service Pack 2.

ewaitfor command

ewaitfor path [max_seconds [delay]]

Wait until the given path exists. The arguments are:

path
The path to test.
max_seconds
The maximum number of seconds to wait for the file to appear. The default is 1 second.
delay
The number of milliseconds to wait between attempts. The default is 100 ms.

Note: The ewaitfor command was implemented in QNX Momentics 6.3.0 Service Pack 2.

exec command

exec [command [argument...]]

Execute a command and/or manipulate file descriptors.

The exec command opens, closes, or copies file descriptors as specified by any I/O redirections given as part of argument. If a command is specified, that command is spawned as a replacement for esh. Any specified arguments are passed to the spawned process.

If esh is operating in restricted mode (-r), you can't use the exec command to run a command whose path starts with a slash.

exit command

exit [n]

Cause esh to exit with the exit status specified by n. If n isn't specified, esh exits with the status of the last command executed.

export command

export name[=word]...
export -p

Mark environment variables for export. This makes them be in the environment of subsequently executed commands. If you specify the -p option, the names and values of all exported variables are written to the standard output.

If restricted mode (-r) is set, you can't use this command.

kill command

kill pid

Set a SIGTERM on the process with process ID pid.

reopen command

reopen [device]

Close standard input, standard output, and standard error and attach them to the specified device. This command is often used in startup scripts. If you don't specify a device, /dev/con1 is used.

If restricted mode (-r) is set, you can't use this command.

set command

set -v

Enable verbose mode; all commands are echoed to the standard output before they're executed.

unset command

unset variable

Unset the specified variable. If restricted mode (-r) is set, you can't use this command.

Examples:

Invoke a subshell:

esh

Invoke a subshell with a script file:

esh /etc/backup

Run the following command and exit:

esh -c "ls /bin"

Files:

/etc/esh
ASCII text file containing shell commands, executed when esh is started as a login shell.

Environment variables:

HOME
The pathname of the user's home directory.
LOGNAME
The user's login name.
PATH
The directory search path used by esh for locating executable programs and esh shell scripts. To change PATH, you must use the export command.

If PATH isn't in the existing environment when esh is invoked, it is set to /bin:/usr/bin. For more information on setting PATH, see "Setting PATH and LD_LIBRARY_PATH" in the Configuring Your Environment chapter of the Neutrino User's Guide.

SHELL
The pathname of the user's preferred shell.
TERM
The terminal type.
TMPDIR
The name of a directory where utilities can create temporary files.
TZ
The timezone setting.

Caveats:

The current version of esh strips out single quotes ('), which means that many common uses of commands such as find fail.

See also:

fesh, ksh, rsh, sh, uesh

Using the Command Line and Writing Shell Scripts in the Neutrino User's Guide


[Previous] [Contents] [Index] [Next]