HomePage > Components and HowTos > CommandLine

Ash Commands

This is a list of the commands used in the Ash shell which is used by Puppy. This man page is not intended to be a tutorial or a complete specification of the shell.

alias : allows defining and viewing of aliases
bg : Run job in the background
break : Break out of enclosing loop bodies (while, until or for)
builtin : Lists all defined builtin commands, and indicates hidden, and internal
cd : chdir : Change the current working directory to that given.
continue : Continue execution at the begining of the enclosing loop
eval : Provides for multiple processing of arguments.
exec : The given program is executed.
exit : Terminate the shell,
export : Prints a list of or marks for export all the variables listed.
false : Any arguments are ignored and the return status is set to 1.
fc : Lists, or edits and re-executes, commands previously entered.
fg : continue the named job (or the current job) in the foreground.
hash : Remember the full pathname of a name argument.
help : Prints out list of Ash commands.
jobs : This command lists out all the background processes which are children of the current shell process.
kill : Stop a processs from running.
let : Perform arithmatic on
local : Create variables.
pwd : Print the current directory you are working in.
read : Read from standard input.
readonly : Mark functions or variables as read only.
return : Exit a shell function.
set : Manipulate shell variables and functions.
setvar : Assigns value to variable.
shift : Shift positional parameters.
times : User and system times.
trap : Run a command when a signal is set.
true : Do nothing sucessfully.
type : Describe a command.
ulimit : Limit user resources.
umask : Mask to create user files.
unalias : Remove an alias.
unset : Remove variable or function names.
wait : Wait for the specified job to complete and return the exit status of the last process in the job.



Overview

The shell is a command that reads lines from either a file or the terminal, interprets them, and generally executes other commands. It is the program that is running when a user logs into the system (although a user can select a different shell with the chsh(1) command). The shell implements a language that has flow control constructs, a macro facility that provides a variety of features in addition to data storage, along with built in history and line editing capabilities. It incorporates many features to aid interactive use and has the advantage that the interpretative language is common to both interactive and non-interactive use (shell scripts). That is, commands can be typed directly to the running shell or can be put into a file and the file can be executed directly by the shell.

Invocation

If no args are present and if the standard input of the shell is connected to a terminal (or if the -i flag is set), the shell is considered an interactive shell. An interactive shell generally prompts before each command and handles programming and command errors differently (as described below). When first starting, the shell inspects argument 0, and if it begins with a dash '-', the shell is also considered a login shell. This is normally done automatically by the system when the user first logs in. A login shell first reads commands from the files /etc/pro­file and .profile if they exist. If the environment variable ENV is set on entry to a shell, or is set in the .profile of a login shell, the shell next reads commands from the file named in ENV. Therefore, a user should place commands that are to be executed only at login time in the .profile file, and commands that are executed for every shell inside the ENV file. To set the ENV variable to some file, place the following line in your .profile of your home directory
ENV=$HOME/.shinit; export ENV

substituting for `.shinit ' any filename you wish. Since the ENV file is read for every invocation of the shell, including shell scripts and non-interactive shells, the following paradigm is useful for restricting commands in the ENV file to interactive invocations. Place commands within the `case ' and `esac ' below (these commands are described later):
case $- in *i*)
# commands for interactive use only
...
esac

If command line arguments besides the options have been specified, then the shell treats the first argument as the name of a file from which to read commands (a shell script), and the remaining arguments are set as the posi­tional parameters of the shell ($1, $2, etc). Otherwise, the shell reads commands from its standard input.

Argument List Processing

All of the single letter options have a corresponding name that can be used as an argument to the '-o' option. The set -o name is provided next to the single letter option in the description below. Specifying a dash `- ' turns the option on, while using a plus `+ ' disables the option. The following options can be set from the command line or with the set(1) builtin (described later).
-a allexport
Export all variables assigned to. (UNIMPLEMENTED for 4.4alpha)
-C noclobber
Don't overwrite existing files with `>'. (UNIMPLEMENTED for 4.4alpha)
-e errexit
If not interactive, exit immediately if any untested command fails. The exit status of a command is considered to be explicitly tested if the command is used to control an if, elif, while, or until; or if the command is the left hand operand of an || operator. -f noglob Disable pathname expansion.
-n noexec
If not interactive, read commands but do not exe­ cute them. This is useful for checking the syntax of shell scripts.
-u nounset
Write a message to standard error when attempting to expand a variable that is not set, and if the shell is not interactive, exit immediately. (UNIM­PLEMENTED for 4.4alpha)
-v verbose
The shell writes its input to standard error as it is read. Useful for debugging.
-x xtrace
Write each command to standard error (preceded by a '+ ') before it is executed. Useful for debugging.
-I ignoreeof
Ignore EOF's from input when interactive.
-i interactive
Force the shell to behave interactively.
-m monitor
Turn on job control (set automatically when inter­active).
-s stdin
Read commands from standard input (set automati­cally if no file arguments are present). This option has no effect when set after the shell has already started running (i.e. with set(1)).
-V vi
Enable the built-in vi(1) command line editor (dis­ ables -E if it has been set).
-E emacs
Enable the built-in emacs(1) command line editor (disables -V if it has been set).
-b notify
Enable asynchronous notification of background job completion. (UNIMPLEMENTED for 4.4alpha)

Lexical Structure

The shell reads input in terms of lines from a file and breaks it up into words at whitespace (blanks and tabs), and at certain sequences of characters that are special to the shell called `operators '. There are two types of operators: control operators and redirection operators (their meaning is discussed later). Following is a list of operators:
Control operators: & && ( ) ; ;; | || <newline>
Redirection operator: < > >| << >> <& >& <<- <>

Quoting

Quoting is used to remove the special meaning of certain characters or words to the shell, such as operators, whitespace, or keywords. There are three types of quot­ing: matched single quotes, matched double quotes, and backslash.

Backslash

A backslash preserves the literal meaning of the following character, with the exception of . A backslash preceding a is treated as a line continuation.

Single Quotes

Enclosing characters in single quotes preserves the lit­eral meaning of all the characters (except single quotes, making it impossible to put single-quotes in a single-quoted string).

Double Quotes

Enclosing characters within double quotes preserves the literal meaning of all characters except dollarsign ($), backquote (`), and backslash (\). The backslash inside double quotes is historically weird, and serves to quote only the following characters: $ ` " \ . Otherwise it remains literal.

Reserved Words

Reserved words are words that have special meaning to the shell and are recognized at the beginning of a line and after a control operator. The following are reserved words:
! elif fi while case
else for then { }
do done until if esac
Their meaning is discussed later.

Aliases

An alias is a name and corresponding value set using the alias(1) builtin command. Whenever a reserved word may occur (see above), and after checking for reserved words, the shell checks the word to see if it matches an alias. If it does, it replaces it in the input stream with its value. For example, if there is an alias called `lf ' with the value `ls -F ', then the input
lf foobar <return>
would become
ls -F foobar <return>

Aliases provide a convenient way for naive users to create shorthands for commands without having to learn how to create functions with arguments. They can also be used to create lexically obscure code. This use is discouraged.

Commands

The shell interprets the words it reads according to a language, the specification of which is outside the scope of this man page (refer to the BNF in the POSIX 1003.2 document). Essentially though, a line is read and if the first word of the line (or after a control operator) is not a reserved word, then the shell has recognized a sim­ple command. Otherwise, a complex command or some other special construct may have been recognized.

Simple Commands

If a simple command has been recognized, the shell per­forms the following actions:
  1. Leading words of the form `name=value ' are stripped off and assigned to the environment of the simple command. Redirection operators and their arguments (as described below) are stripped off and saved for processing.
  2. The remaining words are expanded as described in the section called 'Expansions', and the first remaining word is considered the command name and the command is located. The remaining words are considered the arguments of the command. If no command name resulted, then the `name=value ' variable assignments recognized in 1) affect the current shell.
  3. Redirections are performed as described in the next section.

Redirections

Redirections are used to change where a command reads its input or sends its output. In general, redirections open, close, or duplicate an existing reference to a file. The overall format used for redirection is:
[n] redir-op file

where redir-op is one of the redirection operators men­tioned previously. Following is a list of the possible redirections. The [n] is an optional number, as in '3' (not '[3]'), that refers to a file descriptor.
[n]> file
Redirect standard output (or n) to file.
[n]>| file
Same, but override the -C option.
[n]>> file
Append standard output (or n) to file.
[n]< file
Redirect standard input (or n) from file.
[n1]<&n2
Duplicate standard input (or n1) from file descriptor n2.
[n]<&-
Close standard input (or n).
[n1]>&n2
Duplicate standard output (or n) from n2.
[n]>&-
Close standard output (or n).
[n]<> file
Open file for reading and writing on standard input (or n).
The following redirection is often called a "here-docu­ment".
[n]<< delimiter
here-doc-text...
delimiter

All the text on successive lines up to the delimiter is saved away and made available to the command on standard input, or file descriptor n if it is specified. If the delimiter as specified on the initial line is quoted, then the here-doc-text is treated literally, otherwise the text is subjected to parameter expansion, command substitution, and arithmetic expansion (as described in the section on "Expansions"). If the operator is `<<- ' instead of `<< ', then leading tabs in the here-doc-text are stripped.

Search and Execution

There are three types of commands: shell functions, builtin commands, and normal programs -- and the command is searched for (by name) in that order. They each are executed in a different way. When a shell function is executed, all of the shell posi­tional parameters (except $0, which remains unchanged) are set to the arguments of the shell function. The variables which are explicitly placed in the environment of the com­mand (by placing assignments to them before the function name) are made local to the function and are set to the values given. Then the command given in the function defi­nition is executed. The positional parameters are restored to their original values when the command com­pletes. This all occurs within the current shell.

Shell builtins are executed internally to the shell, without spawning a new process.

Otherwise, if the command name doesn't match a function or builtin, the command is searched for as a normal program in the filesystem (as described in the next section). When a normal program is executed, the shell runs the pro­gram, passing the arguments and the environment to the program. If the program is not a normal executable file (i.e., if it does not begin with the "magic number" whose ASCII representation is "#!", so execve(2) returns ENOEXEC then) the shell will interpret the program in a subshell. The child shell will reinitialize itself in this case, so that the effect will be as if a new shell had been invoked to handle the ad-hoc shell script, except that the loca­tion of hashed commands located in the parent shell will be remembered by the child.

Note that previous versions of this document and the source code itself misleadingly and sporadically refer to a shell script without a magic number as a "shell proce­dure".

To read the rest of this documentation in Puppy go to Start / Help scroll down to Systems-level programs documentation and click on Ash, the shell used by Puppy.

http://www.wlug.org.nz/Shell
http://www.wlug.org.nz/ash(1)
http://linux.about.com/library/cmd/blcmdl1_ash.htm
http://www.debian.org/doc/manuals/reference/ch-program.en.html
http://www.phenix.bnl.gov/WWW/offline/tutorials/debuggingTips.html Ash Shell

Also see
Shells
Sh
Ash
Bash
BashCommands



Categories
CategoryCommandLine
CategoryDevelopment
CategorySoftware
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki