Bash why use let




















What are the advantages and disadvantages of each approach? There is almost no difference between let and. Your examples are invalid. Actually, it IS an arithmetic expression, if only variable bar was set, otherwise bar is treated as zero. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Bash: let statement vs assignment Ask Question. Asked 8 years, 2 months ago. Active 5 years, 6 months ago. Viewed 71k times. Improve this question. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. Asked 4 years, 3 months ago. Active 8 months ago.

Viewed 24k times. Improve this question. Sergiy Kolodyazhnyy Add a comment. Active Oldest Votes. This allows doing simple integer arithmetic, no floating point stuff though. See also. This was likely kept so that old bash scripts don't break. This didn't work in ksh93 , so my guess is that this syntax is bash-specific. The [ with spaces is known as the test command, and you typically see it in decision-making parts.

It is very different in behavior and purpose. Works in bash and ksh Your command here is expr , which takes positional arguments, like expr arg1 arg2 arg3 , so spaces are important. Special parameter 0 is unchanged. All other aspects of the shell execution environment are identical between a function and its caller with these exceptions: the DEBUG and RETURN traps are not inherited unless the function has been given the trace attribute using the declare builtin or the -o functrace option has been enabled with the set builtin, in which case all functions inherit the DEBUG and RETURN traps , and the ERR trap is not inherited unless the -o errtrace shell option has been enabled.

See Bourne Shell Builtins , for the description of the trap builtin. Function invocations that exceed the limit cause the entire command to abort. If the builtin command return is executed in a function, the function completes and execution resumes with the next command after the function call.

Variables local to the function may be declared with the local builtin. These variables are visible only to the function and the commands it invokes. This is particularly important when a shell function calls other functions. Local variables "shadow" variables with the same name declared at previous scopes.

For instance, a local variable declared in a function hides a global variable of the same name: references and assignments refer to the local variable, leaving the global variable unmodified. When the function returns, the global variable is once again visible. With dynamic scoping, visible variables and their values are a result of the sequence of function calls that caused execution to reach the current function. The value of a variable that a function sees depends on its value within its caller, if any, whether that caller is the "global" scope or another shell function.

This is also the value that a local variable declaration "shadows", and the value that is restored when the function returns. For example, if a variable var is declared as local in function func1 , and func1 calls another function func2 , references to var made from within func2 will resolve to the local variable var from func1 , shadowing any global variable named var. The unset builtin also acts using the same dynamic scope: if a variable is local to the current scope, unset will unset it; otherwise the unset will refer to the variable found in any calling scope as described above.

If a variable at the current local scope is unset, it will remain so until it is reset in that scope or until the function returns. Once the function returns, any instance of the variable at a previous scope will become visible.

If the unset acts on a variable at a previous scope, any instance of a variable with that name that had been shadowed will become visible. Function names and definitions may be listed with the -f option to the declare typeset builtin command see Bash Builtins. The -F option to declare or typeset will list the function names only and optionally the source file and line number, if the extdebug shell option is enabled.

Functions may be exported so that subshells automatically have them defined with the -f option to the export builtin see Bourne Shell Builtins. Functions may be recursive. By default, no limit is placed on the number of recursive calls. A parameter is an entity that stores values. It can be a name , a number, or one of the special characters listed below. A variable is a parameter denoted by a name. A variable has a value and zero or more attributes. Attributes are assigned using the declare builtin command see the description of the declare builtin in Bash Builtins.

A parameter is set if it has been assigned a value. The null string is a valid value. Once a variable is set, it may be unset only by using the unset builtin command. If value is not given, the variable is assigned the null string. All value s undergo tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, and quote removal detailed below.

Filename expansion is not performed. Assignment statements may also appear as arguments to the alias , declare , typeset , export , readonly , and local builtin commands declaration commands. This includes arguments to builtin commands such as declare that accept assignment statements declaration commands. A variable can be assigned the nameref attribute using the -n option to the declare or local builtin commands see Bash Builtins to create a nameref , or a reference to another variable.

This allows variables to be manipulated indirectly. A nameref is commonly used within shell functions to refer to a variable whose name is passed as an argument to the function. For instance, if a variable name is passed to a shell function as its first argument, running. If the control variable in a for loop has the nameref attribute, the list of words can be a list of shell variables, and a name reference will be established for each word in the list, in turn, when the loop is executed.

Array variables cannot be given the nameref attribute. However, nameref variables can reference array variables and subscripted array variables. Namerefs can be unset using the -n option to the unset builtin see Bourne Shell Builtins. Otherwise, if unset is executed with the name of a nameref variable as an argument, the variable referenced by the nameref variable will be unset.

A positional parameter is a parameter denoted by one or more digits, other than the single digit 0. Positional parameters may not be assigned to with assignment statements. The set and shift builtins are used to set and unset them see Shell Builtin Commands. The positional parameters are temporarily replaced when a shell function is executed see Shell Functions.

When a positional parameter consisting of more than a single digit is expanded, it must be enclosed in braces. The shell treats several parameters specially. These parameters may only be referenced; assignment to them is not allowed. When the expansion is not within double quotes, each positional parameter expands to a separate word. In contexts where it is performed, those words are subject to further word splitting and filename expansion.

When the expansion occurs within double quotes, it expands to a single word with the value of each parameter separated by the first character of the IFS special variable.

If IFS is unset, the parameters are separated by spaces. If IFS is null, the parameters are joined without intervening separators. In contexts where word splitting is performed, this expands each positional parameter to a separate word; if not within double quotes, these words are subject to word splitting. In contexts where word splitting is not performed, this expands to a single word with each positional parameter separated by a space.

When the expansion occurs within double quotes, and word splitting is performed, each parameter expands to a separate word. If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word. Expands to the current option flags as specified upon invocation, by the set builtin command, or those set by the shell itself such as the -i option.

In a subshell, it expands to the process ID of the invoking shell, not the subshell. Expands to the process ID of the job most recently placed into the background, whether executed as an asynchronous command or using the bg builtin see Job Control Builtins.

This is set at shell initialization. Otherwise, it is set to the filename used to invoke Bash, as given by argument zero. Expansion is performed on the command line after it has been split into token s. There are seven kinds of expansion performed:. The order of expansions is: brace expansion; tilde expansion, parameter and variable expansion, arithmetic expansion, and command substitution done in a left-to-right fashion ; word splitting; and filename expansion.

On systems that can support it, there is an additional expansion available: process substitution. This is performed at the same time as tilde, parameter, variable, and arithmetic expansion and command substitution. After these expansions are performed, quote characters present in the original word are removed unless they have been quoted themselves quote removal.

Only brace expansion, word splitting, and filename expansion can increase the number of words of the expansion; other expansions expand a single word to a single word. After all expansions, quote removal see Quote Removal is performed. Brace expansion is a mechanism by which arbitrary strings may be generated.

This mechanism is similar to filename expansion see Filename Expansion , but the filenames generated need not exist. Patterns to be brace expanded take the form of an optional preamble , followed by either a series of comma-separated strings or a sequence expression between a pair of braces, followed by an optional postscript. The preamble is prefixed to each string contained within the braces, and the postscript is then appended to each resulting string, expanding left to right. Brace expansions may be nested.

The results of each expanded string are not sorted; left to right order is preserved. For example,. When integers are supplied, the expression expands to each number between x and y , inclusive. When either x or y begins with a zero, the shell attempts to force all generated terms to contain the same number of digits, zero-padding where necessary. When characters are supplied, the expression expands to each character lexicographically between x and y , inclusive, using the default C locale. Note that both x and y must be of the same type.

When the increment is supplied, it is used as the difference between each term. The default increment is 1 or -1 as appropriate. Brace expansion is performed before any other expansions, and any characters special to other expansions are preserved in the result. It is strictly textual. Bash does not apply any syntactic interpretation to the context of the expansion or the text between the braces.

A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least one unquoted comma or a valid sequence expression. Any incorrectly formed brace expansion is left unchanged. This construct is typically used as shorthand when the common prefix of the strings to be generated is longer than in the above example:. If none of the characters in the tilde-prefix are quoted, the characters in the tilde-prefix following the tilde are treated as a possible login name.

If this login name is the null string, the tilde is replaced with the value of the HOME shell variable. If HOME is unset, the home directory of the user executing the shell is substituted instead. Otherwise, the tilde-prefix is replaced with the home directory associated with the specified login name. In these cases, tilde expansion is also performed.

Bash also performs tilde expansion on words satisfying the conditions of variable assignments see Shell Parameters when they appear as arguments to simple commands. The parameter name or symbol to be expanded may be enclosed in braces, which are optional but serve to protect the variable to be expanded from characters immediately following it which could be interpreted as part of the name.

The value of parameter is substituted. The parameter is a shell parameter as described above see Shell Parameters or an array reference see Arrays. The braces are required when parameter is a positional parameter with more than one digit, or when parameter is followed by a character that is not to be interpreted as part of its name.

If the first character of parameter is an exclamation point! Bash uses the value formed by expanding the rest of parameter as the new parameter ; this is then expanded and that value is used in the rest of the expansion, rather than the expansion of the original parameter. This is known as indirect expansion.

The value is subject to tilde expansion, parameter expansion, command substitution, and arithmetic expansion. If parameter is a nameref, this expands to the name of the variable referenced by parameter instead of performing the complete indirect expansion. The exclamation point must immediately follow the left brace in order to introduce indirection. In each of the cases below, word is subject to tilde expansion, parameter expansion, command substitution, and arithmetic expansion.

When not performing substring expansion, using the form described below e. Omitting the colon results in a test only for a parameter that is unset. If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted. If parameter is unset or null, the expansion of word is assigned to parameter.

The value of parameter is then substituted. Positional parameters and special parameters may not be assigned to in this way.

If parameter is null or unset, the expansion of word or a message to that effect if word is not present is written to the standard error and the shell, if it is not interactive, exits.

If parameter is null or unset, nothing is substituted, otherwise the expansion of word is substituted. This is referred to as Substring Expansion. It expands to up to length characters of the value of parameter starting at the character specified by offset.

If length is omitted, it expands to the substring of the value of parameter starting at the character specified by offset and extending to the end of the value. If offset evaluates to a number less than zero, the value is used as an offset in characters from the end of the value of parameter. If length evaluates to a number less than zero, it is interpreted as an offset in characters from the end of the value of parameter rather than a number of characters, and the expansion is the characters between offset and that result.

A negative offset is taken relative to one greater than the greatest positional parameter, so an offset of -1 evaluates to the last positional parameter. It is an expansion error if length evaluates to a number less than zero. A negative offset is taken relative to one greater than the maximum index of the specified array. Substring indexing is zero-based unless the positional parameters are used, in which case the indexing starts at 1 by default.

Expands to the names of variables whose names begin with prefix , separated by the first character of the IFS special variable. If name is an array variable, expands to the list of array indices keys assigned in name.

If name is not an array, expands to 0 if name is set and null otherwise. The length in characters of the expanded value of parameter is substituted. If parameter is an indexed array name subscripted by a negative number, that number is interpreted as relative to one greater than the maximum index of parameter , so negative indices count back from the end of the array, and an index of -1 references the last element.

The word is expanded to produce a pattern and matched according to the rules described below see Pattern Matching. The pattern is expanded to produce a pattern just as in filename expansion. Parameter is expanded and the longest match of pattern against its value is replaced with string.

The match is performed according to the rules described below see Pattern Matching. Normally only the first match is replaced. This expansion modifies the case of alphabetic characters in parameter.

Each character in the expanded value of parameter is tested against pattern , and, if it matches the pattern, its case is converted. The pattern should not attempt to match more than one character.

The expansion is either a transformation of the value of parameter or information about parameter itself, depending on the value of operator. Each operator is a single letter:. The expansion is a string that is the value of parameter with lowercase alphabetic characters converted to uppercase.

The expansion is a string that is the value of parameter with the first character converted to uppercase, if it is alphabetic. The expansion is a string that is the value of parameter with uppercase alphabetic characters converted to lowercase.

The expansion is a string that is the value of parameter quoted in a format that can be reused as input. The expansion is a string that is the result of expanding the value of parameter as if it were a prompt string see Controlling the Prompt. The expansion is a string in the form of an assignment statement or declare command that, if evaluated, will recreate parameter with its attributes and value.

Produces a possibly-quoted version of the value of parameter , except that it prints the values of indexed and associative arrays as a sequence of quoted key-value pairs see Arrays. The result of the expansion is subject to word splitting and filename expansion as described below.

Command substitution allows the output of a command to replace the command itself. Command substitution occurs when a command is enclosed as follows:. Bash performs the expansion by executing command in a subshell environment and replacing the command substitution with the standard output of the command, with any trailing newlines deleted.

Embedded newlines are not deleted, but they may be removed during word splitting. The first backquote not preceded by a backslash terminates the command substitution. Command substitutions may be nested. To nest when using the backquoted form, escape the inner backquotes with backslashes.

If the substitution appears within double quotes, word splitting and filename expansion are not performed on the results. Arithmetic expansion allows the evaluation of an arithmetic expression and the substitution of the result. The format for arithmetic expansion is:. The expression is treated as if it were within double quotes, but a double quote inside the parentheses is not treated specially.

All tokens in the expression undergo parameter and variable expansion, command substitution, and quote removal. The result is treated as the arithmetic expression to be evaluated. Arithmetic expansions may be nested. The evaluation is performed according to the rules listed below see Shell Arithmetic.

If the expression is invalid, Bash prints a message indicating failure to the standard error and no substitution occurs. It takes the form of. The process list is run asynchronously, and its input or output appears as a filename. This filename is passed as an argument to the current command as the result of the expansion. When available, process substitution is performed simultaneously with parameter and variable expansion, command substitution, and arithmetic expansion.

The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quotes for word splitting.

If IFS has a value other than the default, then sequences of the whitespace characters space , tab , and newline are ignored at the beginning and end of the word, as long as the whitespace character is in the value of IFS an IFS whitespace character. A sequence of IFS whitespace characters is also treated as a delimiter.

If the value of IFS is null, no word splitting occurs. Explicit null arguments "" or '' are retained and passed to commands as empty strings. Unquoted implicit null arguments, resulting from the expansion of parameters that have no values, are removed. If a parameter with no value is expanded within double quotes, a null argument results and is retained and passed to a command as an empty string.

When a quoted null argument appears as part of a word whose expansion is non-null, the null argument is removed. That is, the word -d'' becomes -d after word splitting and null argument removal. If one of these characters appears, and is not quoted, then the word is regarded as a pattern , and replaced with an alphabetically sorted list of filenames matching the pattern see Pattern Matching.

If no matching filenames are found, and the shell option nullglob is disabled, the word is left unchanged. If the nullglob option is set, and no matches are found, the word is removed. If the failglob shell option is set, and no matches are found, an error message is printed and the command is not executed.

If the shell option nocaseglob is enabled, the match is performed without regard to the case of alphabetic characters. When matching a filename, the slash character must always be matched explicitly by a slash in the pattern, but in other matching contexts it can be matched by a special pattern character as described below see Pattern Matching.

See the description of shopt in The Shopt Builtin , for a description of the nocaseglob , nullglob , failglob , and dotglob options. The filenames. Up: Filename Expansion [ Contents ][ Index ].

Any character that appears in a pattern, other than the special pattern characters described below, matches itself. The NUL character may not occur in a pattern. A backslash escapes the following character; the escaping backslash is discarded when matching. The special pattern characters must be quoted if they are to be matched literally. Matches any string, including the null string. Matches any one of the enclosed characters.

A character class matches any character belonging to that class. If the extglob shell option is enabled using the shopt builtin, several extended pattern matching operators are recognized.

Composite patterns may be formed using one or more of the following sub-patterns:. Complicated extended pattern matching against long strings is slow, especially when the patterns contain alternations and the strings contain multiple matches. Using separate matches against shorter strings, or using arrays of strings instead of a single long string, may be faster.

Before a command is executed, its input and output may be redirected using a special notation interpreted by the shell. Redirection may also be used to modify file handles in the current shell execution environment. The following redirection operators may precede or appear anywhere within a simple command or may follow a command. Redirections are processed in the order they appear, from left to right.

The word following the redirection operator in the following descriptions, unless otherwise noted, is subjected to brace expansion, tilde expansion, parameter expansion, command substitution, arithmetic expansion, quote removal, filename expansion, and word splitting.

If it expands to more than one word, Bash reports an error. Bash handles several filenames specially when they are used in redirections, as described in the following table. If the operating system on which Bash is running provides these special files, bash will use them; otherwise it will emulate them internally with the behavior described below.

If host is a valid hostname or Internet address, and port is an integer port number or service name, Bash attempts to open the corresponding TCP socket. If host is a valid hostname or Internet address, and port is an integer port number or service name, Bash attempts to open the corresponding UDP socket. Redirections using file descriptors greater than 9 should be used with care, as they may conflict with file descriptors the shell uses internally.

Redirection of input causes the file whose name results from the expansion of word to be opened for reading on file descriptor n , or the standard input file descriptor 0 if n is not specified.

Redirection of output causes the file whose name results from the expansion of word to be opened for writing on file descriptor n , or the standard output file descriptor 1 if n is not specified. If the file does not exist it is created; if it does exist it is truncated to zero size. Redirection of output in this fashion causes the file whose name results from the expansion of word to be opened for appending on file descriptor n , or the standard output file descriptor 1 if n is not specified.

If the file does not exist it is created. This construct allows both the standard output file descriptor 1 and the standard error output file descriptor 2 to be redirected to the file whose name is the expansion of word. If it does, other redirection operators apply see Duplicating File Descriptors below for compatibility reasons.

This construct allows both the standard output file descriptor 1 and the standard error output file descriptor 2 to be appended to the file whose name is the expansion of word. This type of redirection instructs the shell to read input from the current source until a line containing only word with no trailing blanks is seen.

All of the lines read up to that point are then used as the standard input or file descriptor n if n is specified for a command. No parameter and variable expansion, command substitution, arithmetic expansion, or filename expansion is performed on word. If any part of word is quoted, the delimiter is the result of quote removal on word , and the lines in the here-document are not expanded. This allows here-documents within shell scripts to be indented in a natural fashion.

The word undergoes tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, and quote removal. Filename expansion and word splitting are not performed. The result is supplied as a single string, with a newline appended, to the command on its standard input or file descriptor n if n is specified.

If word expands to one or more digits, the file descriptor denoted by n is made to be a copy of that file descriptor. If the digits in word do not specify a file descriptor open for input, a redirection error occurs. If n is not specified, the standard input file descriptor 0 is used. If n is not specified, the standard output file descriptor 1 is used. If the digits in word do not specify a file descriptor open for output, a redirection error occurs.

If the file does not exist, it is created. When a simple command is executed, the shell performs the following expansions, assignments, and redirections, from left to right, in the following order. If no command name results, the variable assignments affect the current shell environment.

Otherwise, the variables are added to the environment of the executed command and do not affect the current shell environment. If any of the assignments attempts to assign a value to a readonly variable, an error occurs, and the command exits with a non-zero status. If no command name results, redirections are performed, but do not affect the current shell environment. A redirection error causes the command to exit with a non-zero status. If there is a command name left after expansion, execution proceeds as described below.

Otherwise, the command exits. If one of the expansions contained a command substitution, the exit status of the command is the exit status of the last command substitution performed. If there were no command substitutions, the command exits with a status of zero. After a command has been split into words, if it results in a simple command and an optional list of arguments, the following actions are taken.

When a simple command other than a builtin or shell function is to be executed, it is invoked in a separate execution environment that consists of the following. Unless otherwise noted, the values are inherited from the shell. Command substitution, commands grouped with parentheses, and asynchronous commands are invoked in a subshell environment that is a duplicate of the shell environment, except that traps caught by the shell are reset to the values that the shell inherited from its parent at invocation.

Builtin commands that are invoked as part of a pipeline are also executed in a subshell environment. Subshells spawned to execute command substitutions inherit the value of the -e option from the parent shell.

Otherwise, the invoked command inherits the file descriptors of the calling shell as modified by redirections. When a program is invoked it is given an array of strings called the environment. Bash provides several ways to manipulate the environment. On invocation, the shell scans its own environment and creates a parameter for each name found, automatically marking it for export to child processes.

Executed commands inherit the environment. If the value of a parameter in the environment is modified, the new value becomes part of the environment, replacing the old. The environment for any simple command or function may be augmented temporarily by prefixing it with parameter assignments, as described in Shell Parameters.

These assignment statements affect only the environment seen by that command. If the -k option is set see The Set Builtin , then all parameter assignments are placed in the environment for a command, not just those that precede the command name.

The exit status of an executed command is the value returned by the waitpid system call or equivalent function. Exit statuses fall between 0 and , though, as explained below, the shell may use values above specially. Exit statuses from shell builtins and compound commands are also limited to this range.

Under certain circumstances, the shell will use special values to indicate specific failure modes. A non-zero exit status indicates failure. This seemingly counter-intuitive scheme is used so there is one well-defined way to indicate success and a variety of ways to indicate various failure modes.

If a command is not found, the child process created to execute it returns a status of If a command is found but is not executable, the return status is If a command fails because of an error during expansion or redirection, the exit status is greater than zero. The exit status is used by the Bash conditional commands see Conditional Constructs and some of the list constructs see Lists. All of the Bash builtins return an exit status of zero if they succeed and a non-zero status on failure, so they may be used by the conditional and list constructs.

All builtins return an exit status of 2 to indicate incorrect usage, generally invalid options or missing arguments. Non-builtin commands started by Bash have signal handlers set to the values inherited by the shell from its parent. If Bash is waiting for a command to complete and receives a signal for which a trap has been set, the trap will not be executed until the command completes.

When Bash is waiting for an asynchronous command via the wait builtin, the reception of a signal for which a trap has been set will cause the wait builtin to return immediately with an exit status greater than , immediately after which the trap is executed. A shell script is a text file containing shell commands. When such a file is used as the first non-option argument when invoking Bash, and neither the -c nor -s option is supplied see Invoking Bash , Bash reads and executes commands from the file, then exits.

This mode of operation creates a non-interactive shell. When Bash runs a shell script, it sets the special parameter 0 to the name of the file, rather than the name of the shell, and the positional parameters are set to the remaining arguments, if any are given. If no additional arguments are supplied, the positional parameters are unset. A shell script may be made executable by using the chmod command to turn on the execute bit.

In other words, executing. This subshell reinitializes itself, so that the effect is as if a new shell had been invoked to interpret the script, with the exception that the locations of commands remembered by the parent see the description of hash in Bourne Shell Builtins are retained by the child.

Thus, you can specify Bash, awk , Perl, or some other interpreter and write the rest of the script file in that language. The arguments to the interpreter consist of one or more optional arguments following the interpreter name on the first line of the script file, followed by the name of the script file, followed by the rest of the arguments supplied to the script.

The details of how the interpreter line is split into an interpreter name and a set of arguments vary across systems. Bash will perform this action on operating systems that do not handle it themselves. Bash scripts often begin with! Builtin commands are contained within the shell itself. When the name of a builtin command is used as the first word of a simple command see Simple Commands , the shell executes the command directly, without invoking another program.

Builtin commands are necessary to implement functionality impossible or inconvenient to obtain with separate utilities. This section briefly describes the builtins which Bash inherits from the Bourne Shell, as well as the builtin commands which are unique to or have been extended in Bash. Several builtin commands are described in other chapters: builtin commands which provide the Bash interface to the job control facilities see Job Control Builtins , the directory stack see Directory Stack Builtins , the command history see Bash History Builtins , and the programmable completion facilities see Programmable Completion Builtins.

The following shell builtin commands are inherited from the Bourne Shell. Do nothing beyond expanding arguments and performing redirections. The return status is zero. Read and execute commands from the filename argument in the current shell context. If filename does not contain a slash, the PATH variable is used to find filename.

If any arguments are supplied, they become the positional parameters when filename is executed. Otherwise the positional parameters are unchanged. The return status is the exit status of the last command executed, or zero if no commands are executed. If filename is not found, or cannot be read, the return status is non-zero. This builtin is equivalent to source.

Exit from a for , while , until , or select loop. If n is supplied, the n th enclosing loop is exited. The return status is zero unless n is not greater than or equal to 1. Change the current working directory to directory. If directory is not supplied, the value of the HOME shell variable is used.

Any additional arguments following directory are ignored. If the -e option is supplied with -P and the current working directory cannot be successfully determined after a successful directory change, cd will return an unsuccessful status.

On systems that support it, the - option presents the extended attributes associated with a file as a directory. Resume the next iteration of an enclosing for , while , until , or select loop. If n is supplied, the execution of the n th enclosing loop is resumed. The arguments are concatenated together into a single command, which is then read and executed, and its exit status returned as the exit status of eval. If there are no arguments or only empty arguments, the return status is zero. If command is supplied, it replaces the shell without creating a new process.

If the -l option is supplied, the shell places a dash at the beginning of the zeroth argument passed to command. This is what the login program does. The -c option causes command to be executed with an empty environment. If -a is supplied, the shell passes name as the zeroth argument to command.

If command cannot be executed for some reason, a non-interactive shell exits, unless the execfail shell option is enabled. In that case, it returns failure. An interactive shell returns failure if the file cannot be executed. A subshell exits unconditionally if exec fails. If no command is specified, redirections may be used to affect the current shell environment. If there are no redirection errors, the return status is zero; otherwise the return status is non-zero.

If n is omitted, the exit status is that of the last command executed. Any trap on EXIT is executed before the shell terminates.



0コメント

  • 1000 / 1000