Linux "dash" Command Line Options and Examples
command interpreter

dash is the standard command interpreter for the system. The current version of dash is in the process of being changed to conform with the POSIX 1003.2 and 1003.


Usage:

dash [-aCefnuvxIimqVEbp] [+aCefnuvxIimqVEbp] [-o option_name] [+o option_name] [command_file [argument ...]]
dash -c [-aCefnuvxIimqVEbp] [+aCefnuvxIimqVEbp] [-o option_name] [+o option_name] command_string [command_name [argument ...]]
dash -s [-aCefnuvxIimqVEbp] [+aCefnuvxIimqVEbp] [-o option_name] [+o option_name] [argument ...]






Command Line Options:

-a
allexport Export all variables assigned to.
dash -a ...
-C
noclobber Don't overwrite existing files with “>”.
dash -C ...
-f
noglob Disable pathname expansion.
dash -f ...
-v
verbose The shell writes its input to standard error as it is read. Useful for debugging.
dash -v ...
-x
xtrace Write each command to standard error (preceded by a ‘+ ’) before it is executed. Useful for debugging.
dash -x ...
-I
ignoreeof Ignore EOF's from input when interactive.
dash -I ...
-i
interactive Force the shell to behave interactively.
dash -i ...
-l
Make dash act as if it had been invoked as a login shell.
dash -l ...
-m
monitor Turn on job control (set automatically when interactive).
dash -m ...
-V
vi Enable the built-in vi(1) command line editor (disables -E if it has been set).
dash -V ...
-E
emacs Enable the built-in emacs(1) command line editor (disables -V if it has been set).
dash -E ...
-b
notify Enable asynchronous notification of background job completion. (UNIMPLEMENTED for 4.4alpha)
dash -b ...
-p
search for command using a PATH that guarantees to find all the standard utilities.
dash -p ...
-e
Use the editor named by editor to edit the commands. The editor string is a command name, subject to search via the PATHvariable. The value in the FCEDIT variable is used as a default when -e is not specified. If FCEDIT is null or unset,the value of the EDITOR variable is used. If EDITOR is null or unset, ed(1) is used as the editor.
dash -e ...
-n
Suppress command numbers when listing with -l.
dash -n ...
-r
Reverse the order of the commands listed (with -l) or edited (with neither -l nor -s).
dash -r ...
-s
firstlast Select the commands to list or edit. The number of previous commands that can be accessed are determined by the value ofthe HISTSIZE variable. The value of first or last or both are one of the following:[+]numberA positive number representing a command number; command numbers can be displayed with the -l option.
dash -s ...
-number
A negative decimal number representing the command that was executed number of commands previously. For example,
dash -number ...
-1
stringA string indicating the most recently entered command that begins with that string. If the old=new operand is not alsospecified with -s, the string form of the first operand cannot contain an embedded equal sign.The following environment variables affect the execution of fc:FCEDIT Name of the editor to use.HISTSIZE The number of previous commands that are accessible.fg [job]Move the specified job or the current job to the foreground.getopts optstring varThe POSIX getopts command, not to be confused with the Bell Labs -derived getopt(1).The first argument should be a series of letters, each of which may be optionally followed by a colon to indicate that theoption requires an argument. The variable specified is set to the parsed option.The getopts command deprecates the older getopt(1) utility due to its handling of arguments containing whitespace.The getopts builtin may be used to obtain options and their arguments from a list of parameters. When invoked, getopts placesthe value of the next option from the option string in the list in the shell variable specified by var and its index in theshell variable OPTIND. When the shell is invoked, OPTIND is initialized to 1. For each option that requires an argument, thegetopts builtin will place it in the shell variable OPTARG. If an option is not allowed for in the optstring, then OPTARG willbe unset.optstring is a string of recognized option letters (see getopt(3)). If a letter is followed by a colon, the option is expectedto have an argument which may or may not be separated from it by white space. If an option character is not found whereexpected, getopts will set the variable var to a “?”; getopts will then unset OPTARG and write output to standard error. Byspecifying a colon as the first character of optstring all errors will be ignored.A nonzero value is returned when the last option is reached. If there are no remaining arguments, getopts will set var to thespecial option, “--”, otherwise, it will set var to “?”.The following code fragment shows how one might process the arguments for a command that can take the options [a] and [b], andthe option [c], which requires an argument.while getopts abc: fdocase $f ina | b) flag=$f;;c) carg=$OPTARG;;\?) echo $USAGE; exit 1;;esacdoneshift `expr $OPTIND - 1`This code will accept any of the following as equivalent:cmd -acarg file filecmd -a -c arg file filecmd -carg -a file filecmd -a -carg -- file filehash -rv command ...The shell maintains a hash table which remembers the locations of commands. With no arguments whatsoever, the hash commandprints out the contents of this table. Entries which have not been looked at since the last cd command are marked with anasterisk; it is possible for these entries to be invalid.With arguments, the hash command removes the specified commands from the hash table (unless they are functions) and then locatesthem. With the -v option, hash prints the locations of the commands as it finds them. The -r option causes the hash command todelete all the entries in the hash table except for functions.pwd [-LP]builtin command remembers what the current directory is rather than recomputing it each time. This makes it faster. However,if the current directory is renamed, the builtin version of pwd will continue to print the old name for the directory. The -Poption causes the physical value of the current working directory to be shown, that is, all symbolic links are resolved to theirrespective values. The -L option turns off the effect of any preceding -P options.read [-p prompt] [-r] variable [...]The prompt is printed if the -p option is specified and the standard input is a terminal. Then a line is read from the standardinput. The trailing newline is deleted from the line and the line is split as described in the section on word splitting above,and the pieces are assigned to the variables in order. At least one variable must be specified. If there are more pieces thanvariables, the remaining pieces (along with the characters in IFS that separated them) are assigned to the last variable. Ifthere are more variables than pieces, the remaining variables are assigned the null string. The read builtin will indicate suc‐cess unless EOF is encountered on input, in which case failure is returned.By default, unless the -r option is specified, the backslash “\” acts as an escape character, causing the following character tobe treated literally. If a backslash is followed by a newline, the backslash and the newline will be deleted.readonly name ...readonly -pThe specified names are marked as read only, so that they cannot be subsequently modified or unset. The shell allows the valueof a variable to be set at the same time it is marked read only by writingreadonly name=valueWith no arguments the readonly command lists the names of all read only variables. With the -p option specified the output willbe formatted suitably for non-interactive use.printf format [arguments ...]printf formats and prints its arguments, after the first, under control of the format. The format is a character string whichcontains three types of objects: plain characters, which are simply copied to standard output, character escape sequences whichare converted and copied to the standard output, and format specifications, each of which causes printing of the next successiveargument.The arguments after the first are treated as strings if the corresponding format is either b, c or s; otherwise it is evaluatedas a C constant, with the following extensions:· A leading plus or minus sign is allowed.· If the leading character is a single or double quote, the value is the ASCII code of the next character.The format string is reused as often as necessary to satisfy the arguments. Any extra format specifications are evaluated withzero or the null string.Character escape sequences are in backslash notation as defined in ANSI X3.159-1989 (“ANSI C89”). The characters and theirmeanings are as follows:\a Write a <bell> character.\b Write a <backspace> character.\e Write an <escape> (ESC) character.\f Write a <form-feed> character.\n Write a <new-line> character.\r Write a <carriage return> character.\t Write a <tab> character.\v Write a <vertical tab> character.\\ Write a backslash character.\num Write an 8-bit character whose ASCII value is the 1-, 2-, or 3-digit octal number num.Each format specification is introduced by the percent character (``%''). The remainder of the format specification includes,in the following order:Zero or more of the following flags:# A `#' character specifying that the value should be printed in an ``alternative form''. For b, c, d, and s for‐mats, this option has no effect. For the o format the precision of the number is increased to force the firstcharacter of the output string to a zero. For the x (X) format, a non-zero result has the string 0x (0X)prepended to it. For e, E, f, g, and G formats, the result will always contain a decimal point, even if no dig‐its follow the point (normally, a decimal point only appears in the results of those formats if a digit followsthe decimal point). For g and G formats, trailing zeros are not removed from the result as they would otherwisebe.
dash -1 ...
-
+ A `+' character specifying that there should always be a sign placed before the number when using signed for‐mats.‘ ’ A space specifying that a blank should be left before a positive number for a signed format. A `+' overrides aspace if both are used;0 A zero `0' character indicating that zero-padding should be used rather than blank-padding. A `-' overrides a`0' if both are used;Field Width:An optional digit string specifying a field width; if the output string has fewer characters than the field width itwill be blank-padded on the left (or right, if the left-adjustment indicator has been given) to make up the field width(note that a leading zero is a flag, but an embedded zero is part of a field width);Precision:An optional period, ‘.’, followed by an optional digit string giving a precision which specifies the number of digits toappear after the decimal point, for e and f formats, or the maximum number of bytes to be printed from a string (b and sformats); if the digit string is missing, the precision is treated as zero;Format:A character which indicates the type of format to use (one of diouxXfwEgGbcs).A field width or precision may be ‘*’ instead of a digit string. In this case an argument supplies the field width or preci‐sion.The format characters and their meanings are:diouXx The argument is printed as a signed decimal (d or i), unsigned octal, unsigned decimal, or unsigned hexadecimal (Xor x), respectively.f The argument is printed in the style [-]ddd.ddd where the number of d's after the decimal point is equal to the pre‐cision specification for the argument. If the precision is missing, 6 digits are given; if the precision is explic‐itly 0, no digits and no decimal point are printed.eE The argument is printed in the style [-]d.ddde±dd where there is one digit before the decimal point and the numberafter is equal to the precision specification for the argument; when the precision is missing, 6 digits are pro‐duced. An upper-case E is used for an `E' format.gG The argument is printed in style f or in style e (E) whichever gives full precision in minimum space.b Characters from the string argument are printed with backslash-escape sequences expanded.The following additional backslash-escape sequences are supported:\c Causes dash to ignore any remaining characters in the string operand containing it, any remaining string op‐erands, and any additional characters in the format operand.\0num Write an 8-bit character whose ASCII value is the 1-, 2-, or 3-digit octal number num.c The first character of argument is printed.s Characters from the string argument are printed until the end is reached or until the number of bytes indicated bythe precision specification is reached; if the precision is omitted, all characters in the string are printed.% Print a `%'; no argument is used.In no case does a non-existent or small field width cause truncation of a field; padding takes place only if the specified fieldwidth exceeds the actual width.set [{ -options | +options | -- }] arg ...The set command performs three different functions.With no arguments, it lists the values of all shell variables.If options are given, it sets the specified option flags, or clears them as described in the section called Argument ListProcessing. As a special case, if the option is -o or +o and no argument is supplied, the shell prints the settings of all itsoptions. If the option is -o, the settings are printed in a human-readable format; if the option is +o, the settings areprinted in a format suitable for reinput to the shell to affect the same option settings.The third use of the set command is to set the values of the shell's positional parameters to the specified args. To change thepositional parameters without changing any options, use “--” as the first argument to set. If no args are present, the set com‐mand will clear all the positional parameters (equivalent to executing “shift $#”.)shift [n]Shift the positional parameters n times. A shift sets the value of $1 to the value of $2, the value of $2 to the value of $3,and so on, decreasing the value of $# by one. If n is greater than the number of positional parameters, shift will issue anerror message, and exit with return status 2.test expression[ expression ]The test utility evaluates the expression and, if it evaluates to true, returns a zero (true) exit status; otherwise it returns1 (false). If there is no expression, test also returns 1 (false).All operators and flags are separate arguments to the test utility.The following primaries are used to construct expression:
dash - ...
-c
file True if file exists and is a character special file.
dash -c ...
-d
file True if file exists and is a directory.
dash -d ...
-g
file True if file exists and its set group ID flag is set.
dash -g ...
-h
file True if file exists and is a symbolic link.
dash -h ...
-k
file True if file exists and its sticky bit is set.
dash -k ...
-t
True if the file whose file descriptor number is file_descriptor is open and is associated with a terminal.
dash -t ...
-u
file True if file exists and its set user ID flag is set.
dash -u ...
-z
string True if the length of string is zero.
dash -z ...
-O
file True if file exists and its owner matches the effective user id of this process.
dash -O ...
-G
file True if file exists and its group matches the effective group id of this process.
dash -G ...
-S
file1 -nt file2True if file1 and file2 exist and file1 is newer than file2.file1 -ot file2True if file1 and file2 exist and file1 is older than file2.file1 -ef file2True if file1 and file2 exist and refer to the same file.string True if string is not the null string.s1 = s2 True if the strings s1 and s2 are identical.s1 != s2 True if the strings s1 and s2 are not identical.s1 < s2 True if string s1 comes before s2 based on the ASCII value of their characters.s1 > s2 True if string s1 comes after s2 based on the ASCII value of their characters.n1 -eq n2 True if the integers n1 and n2 are algebraically equal.n1 -ne n2 True if the integers n1 and n2 are not algebraically equal.n1 -gt n2 True if the integer n1 is algebraically greater than the integer n2.n1 -ge n2 True if the integer n1 is algebraically greater than or equal to the integer n2.n1 -lt n2 True if the integer n1 is algebraically less than the integer n2.n1 -le n2 True if the integer n1 is algebraically less than or equal to the integer n2.These primaries can be combined with the following operators:! expression True if expression is false.expression1 -a expression2True if both expression1 and expression2 are true.expression1 -o expression2True if either expression1 or expression2 are true.(expression) True if expression is true.The -a operator has higher precedence than the -o operator.times Print the accumulated user and system times for the shell and for processes run from the shell. The return status is 0.trap [action signal ...]Cause the shell to parse and execute action when any of the specified signals are received. The signals are specified by signalnumber or as the name of the signal. If signal is 0 or EXIT, the action is executed when the shell exits. action may be empty(''), which causes the specified signals to be ignored. With action omitted or set to `-' the specified signals are set totheir default action. When the shell forks off a subshell, it resets trapped (but not ignored) signals to the default action.The trap command has no effect on signals that were ignored on entry to the shell. trap without any arguments cause it to writea list of signals and their associated action to the standard output in a format that is suitable as an input to the shell thatachieves the same trapping results.Examples:trapList trapped signals and their corresponding actiontrap '' INT QUIT tstp 30Ignore signals INT QUIT TSTP USR1trap date INTPrint date upon receiving signal INTtype [name ...]Interpret each name as a command and print the resolution of the command search. Possible resolutions are: shell keyword,alias, shell builtin, command, tracked alias and not found. For aliases the alias expansion is printed; for commands andtracked aliases the complete pathname of the command is printed.ulimit [-H | -S] [-a | -tfdscmlpn [value]]Inquire about or set the hard or soft limits on processes or set new limits. The choice between hard limit (which no process isallowed to violate, and which may not be raised once it has been lowered) and soft limit (which causes processes to be signaledbut not necessarily killed, and which may be raised) is made with these flags:
dash -S ...
-H
set or inquire about hard limits
dash -H ...