Ksh Error Codes
Contents |
>ExampleComments1Catchall for general errorslet "var1 = 1/0"Miscellaneous errors, such as "divide by zero" and other impermissible operations2Misuse of shell ksh exit code builtins (according to Bash documentation)empty_function() {}Missing keyword or command, or permission
Ksh Error Handling
problem (and diff return code on a failed binary file comparison).126Command invoked cannot execute/dev/nullPermission problem or command is not an executable127"command not found"illegal_commandPossible problem with $PATH or a typo128Invalid argument to exit
Bash Exit Codes
>exit 3.14159exit takes only integer args in the range 0 - 255 (see first footnote)128+nFatal error signal "n"kill -9 $PPID of script$? returns 137 (128 + 9)130Script terminated by Control-CCtl-CControl-C is fatal error signal 2, (130 = 128 + 2, see above)255*Exit status out of rangeexit -1exit takes only integer args in the range 0 - 255
Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. Search Forums Show Threads Show Posts
Bash Assign Exit Code To Variable
Tag Search Advanced Search Unanswered Threads Find All Thanked Posts Go to Page...
Ksh Return
learn unix and linux commands Exit codes in Korn shell UNIX for Advanced & Expert Users ksh if Thread Tools Search this Thread Display Modes #1 03-15-2006 miltony Registered User Join Date: Sep 2005 Last Activity: 16 January 2008, 1:29 AM EST Posts: 10 Thanks: 0 Thanked 1 Time http://tldp.org/LDP/abs/html/exitcodes.html in 1 Post Exit codes in Korn shell Hi, Can anyone give me the explanation for the exit codes 1 and 127 returned from Korn shell. Thanks in advance. Remove advertisements Sponsored Links miltony View Public Profile Find all posts by miltony #2 03-15-2006 matrixmadhan Technorati Master Join Date: Mar 2005 Last Activity: 3 October 2016, 6:30 AM EDT Location: classification algos Posts: 3,206 Thanks: 19 Thanked http://www.unix.com/unix-for-advanced-and-expert-users/25981-exit-codes-korn-shell.html 30 Times in 27 Posts 127 - exit status returned when command executed is not found 1 - there could be many reasons like word expansion, redirection return value from command executed over the interpreter Remove advertisements Sponsored Links matrixmadhan View Public Profile Find all posts by matrixmadhan #3 03-15-2006 jim mcnamara ...@... Join Date: Feb 2004 Last Activity: 19 October 2016, 9:50 PM EDT Location: NM Posts: 10,838 Thanks: 451 Thanked 971 Times in 902 Posts Actually assuming the codes mean something when you run somebody else's code can be a stretch. The defacto standard for these things comes from BSD's sysexits.h See: http://www.hmug.org/man/3/sysexits.php for an explanation of "standard" exit codes, proposed to be standard anyway. The Linux Documentation Project has an unofficial guide - http://www.tldp.org/LDP/abs/html/unofficialst.html Remove advertisements Sponsored Links jim mcnamara View Public Profile Find all posts by jim mcnamara « Previous Thread | Next Thread » Thread Tools Show Printable Version Email this Page Subscribe to this Thread Display Modes Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Search this Thread Advanced Search More UNIX and Linux Forum Topics You Might Find Helpful Thread Thread Starter Forum Replies Last Post Bash Shell Script Exit Codes metallica1973 Shell Programming and Scripting 6 01-
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about http://unix.stackexchange.com/questions/76162/how-do-i-capture-the-return-status-and-use-tee-at-the-same-time-in-korn-shell hiring developers or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask http://www.well.ox.ac.uk/~johnb/comp/unix/ksh.html Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top How do I capture the return status and use tee exit code at the same time in korn shell? [duplicate] up vote 4 down vote favorite 3 This question already has an answer here: Get exit status of process that's piped to another 15 answers Consider Source code: 1. Parent.sh #!/usr/bin/ksh # No tee ksh Child.sh; exit_status=$?; echo "Exit status: ${exit_status}" # Using tee ksh Child.sh | tee -a log.txt; exit_status=$?; echo "Exit status: ${exit_status}" 2. Child.sh #!/usr/bin/ksh ... exit 1; Output: Exit status: 1 Exit status: 0 Variable $exit_status is capturing ksh error codes the exit status of Child.sh and so is 1. In the 2nd case, $exit_status is capturing the exit status of tee, which is 0. So how do I capture the exit status and also use tee? shell-script ksh share|improve this question edited May 17 '13 at 9:06 asked May 17 '13 at 8:10 Kent Pawar 53231025 marked as duplicate by lesmana, Stéphane Chazelas, jasonwryan, slm♦, vonbrand May 17 '13 at 12:39 This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. Hi @lesmana - Note that this question is asking for a ksh solution. Using $PIPESTATUS only works in bash - all solution I can find on unix.stackexchange.com are for bash. –Kent Pawar May 17 '13 at 8:46 Seems the solution (workaround) for ksh is to use Pipefail.. I will test and confirm the same assuming this question is not incorrectly closed by then.. –Kent Pawar May 17 '13 at 8:49 1 I am aware that this question is marked ksh. I suggested the duplicate because the other question is not marked as bash specific and not all answers are bash specific. –lesmana May 17 '13 at 8:52 In answers to that other question, you'll find POSIX answers. See also the comp.unix.shell FAQ –Stéphane Chazelas May 17 '13 at 9:01 Gotcha @lesmana. Well this solution expl
Variables Action on Success or Failure of a Command Trivial Calculations Numerical Calculations using "bc" "grep" "sed" "awk" "perl" Principle of Script Defining the Shell Type To make a ksh script (which is a ksh program) crate a new file with a starting line like: #!/usr/bin/ksh It is important that the path to the ksh is propper and that the line doesn not have more than 32 characters. The shell from which you are starting the script will find this line and and hand the whole script over to to ksh. Without this line the script would be interpreted by the same typ of shell as the one, from which it was started. But since the syntax is different for all shells, it is necessary to define the shell with that line. Four Types of Lines A script has four types of lines: The shell defining line at the top, empty lines, commentary lines starting with a # and command lines. See the following top of a script as an example for these types of lines: #!/usr/bin/ksh # Commentary...... file=/path/file if [[ $file = $1 ]];then command fi Start and End of Script The script starts at the first line and ends either when it encounters an "exit" or the last line. All "#" lines are ignored. Start and End of Command A command starts with the first word on a line or if it's the second command on a line with the first word after a";'. A command ends either at the end of the line or whith a ";". So one can put several commands onto one line: print -n "Name: "; read name; print "" One can continue commands over more than one line with a "\" immediately followed by a newline sign which is made be the return key: grep filename | sort -u | awk '{print $4}' | \ uniq -c >> /longpath/file Name and Permissions of Script File The script mus not have a name which is identical to a unix command: So the script must NOT be called "test"! After saveing the file give it the execute permissions with: chmod 700 filename. Variables Filling in When filling into a variable then one uses just it's name: state="US" and no blanks. There is