Active Oldest Votes. Are you sure you don't have a typo in your question? But why not use newer ksh math evaluation features maybe this will fix your problem. Improve this answer. The Overflow Blog. Podcast Explaining the semiconductor shortage, and how it might end. Viewed 1k times. Improve this question. This is Bash Pitfall 4 , save that link, you'll need it if you face other issues with shell programming.
You had ksh instead of bash but many parts will apply. Also see the difference between [ and [[ — ilkkachu. You can use set -x to the shebang line to enable verbose debug mode to see what exactly is happening while executing the script. Add a comment. Active Oldest Votes.
Edit: It seems that at least Bash will have issues with the number , it interprets it as octal. This command is also available as an executable; see kill. If all expressions are successfully evaluated, the exit status is:. If an error occurs during the parsing or evaluation of an expression, the exit status is greater than 1. Since expressions may need to be quoted, expr is syntactic sugar for let " expr ".
Print the arguments on the standard output, separated by spaces, and terminated with a newline. The -n option suppresses the newline. By default, certain C escapes are translated. You can inhibit backslash expansion by using the -r option. As above, the -n option suppresses the trailing newline. Print the present working directory. If -L option is used or if the physical option see the set command below isn't set, the logical path is printed i.
If -P option physical path is used or if the physical option is set, the path determined from the filesystem by following.. This command is also available as an executable; see pwd. If there are more parameters than fields, the extra parameters are set to null, or alternatively, if there are more fields than parameters, the last parameter is assigned the remaining fields inclusive of any separating spaces.
If the input-line ends in a backslash and the -r option wasn't used, the backslash and newline are stripped and more input is read. If no input is read, read exits with a nonzero status.
The first parameter may have a question mark and a string appended to it, in which case the string is used as a prompt printed to standard error before any input is read if the input is a tty e. If the -s option is used, input is saved to the history file. Set the readonly attribute of the named parameters. If values are given, parameters are set to them before setting the attribute. Once a parameter is made readonly, it can't be unset and its value can't be changed.
If no parameters are specified, the names of all parameters with the readonly attribute are printed one per line, unless the -p option is used, in which case readonly commands defining all readonly parameters, including their values, are printed.
Return from a function or. If no status is given, the exit status of the last executed command is used. If used outside of a function or. The following table lists both option letters if they exist and long names along with a description of what the option does.
When -s is used in the set command, it causes the specified arguments to be sorted before assigning them to the positional parameters or to array name , if -A is used. These options can also be used upon invocation of the shell. You can find the current set of options with single letter names in the parameter -. Remaining arguments, if any, are positional parameters and are assigned, in order, to the positional parameters i.
If options are ended with -- and there are no remaining arguments, all positional parameters are cleared. If no options or arguments are given, then the values of all names are printed. For unknown historical reasons, a lone - option is treated specially: it clears both the -x and -v options. The number defaults to 1. Evaluate the expression and return zero status if true, and 1 status if false and greater than 1 if there was an error. It's normally used as the condition command of if and while statements.
You can combine the above basic expressions, in which unary operators have precedence over binary operators, with the following operators listed in increasing order of precedence :.
Note that some special rules are applied courtesy of POSIX if the number of arguments to test or [ … ] is less than five: if leading!
Print the accumulated user and system times used by the shell and by processes which have exited that the shell started. The handler is either a null string, indicating the signals are to be ignored, a minus - , indicating that the default action is to be taken for the signals see signal , or a string containing shell commands to be evaluated and executed at the first opportunity i. The signal is the name of a signal e. There are two special signals:. EXIT handlers are executed in the environment of the last executed command.
Note that for noninteractive shells, the trap handler can't be changed for signals that were ignored when the shell started. With no arguments, trap lists, as a series of trap commands, the current state of the traps that have been set since the shell started. This command is also available as an executable; see true. Display or set parameter attributes. Values for parameters may optionally be specified. If typeset is used inside a function, any newly created parameters are local to the function.
When -f is used, typeset operates on the attributes of functions. As with parameters, if no names are given, functions are listed with their values i. For functions, -t is the trace attribute. When functions with the trace attribute are executed, the xtrace -x shell option is temporarily turned on. For functions, -u is the undefined attribute. Display or set process limits. If no options are used, the file size limit -f is assumed. The value , if specified, may be either be an arithmetic expression or the word unlimited.
The limits affect the shell and any processes created by the shell after they're imposed. Note that some systems may not allow limits to be increased once they are set. Also note that the types of limits available are system dependent — some systems have only the -f limit.
Display or set the file permission creation mask, or umask see umask. If the -S option is used, the mask displayed or set is symbolic, otherwise it's an octal number. This command is also available as an executable; see umask.
Symbolic masks are like those used by chmod :. The who part specifies which part of the umask is to be modified. The letters mean:. The op part indicates how the who permissions are to be modified:. When symbolic masks are used, they describe what permissions may be made available as opposed to octal masks in which a set bit means the corresponding bit is to be cleared.
Remove the aliases for the given names. If the -a option is used, all aliases are removed. If the -t or -d option is used, the indicated operations are carried out on tracked or directory aliases, respectively. Unset the named parameters -v , the default or functions -f. The exit status is nonzero if any of the parameters were already unset, zero otherwise.
Wait for the specified job s to finish. If no jobs are specified, wait waits for all currently running jobs if any to finish and exits with a zero status. If job monitoring is enabled, the completion status of jobs is printed this isn't the case when jobs are explicitly specified.
For each name, the type of command is listed reserved word, builtin, alias, function, tracked alias or executable. If the -p option is used, a path search is done even if name is a reserved word, alias, and so on. Without the -v option, whence is similar to command -v except that whence finds reserved words and doesn't print aliases as alias commands; with the -v option, whence is the same as command -V.
Note that for whence , the -p option doesn't affect the search path used, as it does for command. If the type of one or more of the names couldn't be determined, the exit status is nonzero.
Job control refers to the shell's ability to monitor and control jobs , which are processes or groups of processes created for commands or pipelines. At a minimum, the shell keeps track of the status of the background i. If job control is fully enabled using set -m or set -o monitor , as it is for interactive shells, the processes of a job are placed in their own process group, you can stop foreground jobs by typing the suspend character from the terminal normally Ctrl - Z , you can restart jobs in either the foreground or background, using the fg and bg commands, and the state of the terminal is saved or restored when a foreground job is stopped or restarted.
Note that you can stop only commands that create processes e. When a job is created, it's assigned a job number. For interactive shells, this number is printed inside […] , followed by the process IDs of the processes in the job when an asynchronous command is run.
You can also use other percent sequences to refer to jobs:. When a job changes state e. When an attempt is made to exit the shell while there are jobs in the stopped state, the shell warns the user that there are stopped jobs and doesn't exit. If another attempt is immediately made to exit the shell, the stopped jobs are sent a SIGHUP signal and the shell exits.
Similarly, if the nohup option isn't set and there are running jobs when an attempt is made to exit a login shell, the shell warns the user and doesn't exit. If another attempt is immediately made to exit the shell, the running jobs are sent a SIGHUP signal and the shell exits.
When the emacs option is set, interactive input-line editing is enabled. In this mode, various editing commands typically bound to one or more control characters cause immediate actions without waiting for a new-line.
There are happily no declarations of variables needed in ksh. One cannot have decimals only integers. One can skip the rest of a loop and directly go to the next iteration with: " continue ". The arguments cannot directly be modified but one can reset the hole commandline for another part of the program. One can iterate over the command line arguments with the help of the shift command.
Shift indirectly removes the first argument. To compare numbers one uses " -eq " for equal " -ne " for not equal as well as " -gt " for greater than and "-lt" for less than.
Ksh has it's own regular expressions. So to get all the files ending it. A single character is represented with a? So all the files starting with any sign followed bye Especially in ksh there are quantifiers for whole patterns:? It knows all the variables from the calling shell except the commandline arguments.
But has it's own command line arguments so that one can call it with different values from different places in the script. It has an exit status but cannot return a value like a c funcition can.
To call it just put it's name in the script: foo.
0コメント