English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am running a ksh script. In the if clause the condition is [$? -eq 0]. what does $? mean. I know it is comparing with zero. But to what.

2006-08-10 16:45:32 · 3 answers · asked by pradeep k 1 in Computers & Internet Programming & Design

3 answers

I just checked, and it seems to be checking the return value of the last command to make sure it was successful (most programs return 0 when they work properly). I tried it in ksh, and I checked the man pages to see what the ? is. Here's what it said:

? The decimal value returned by the last executed command.

Here's the man page: http://www.hmug.org/man/1/ksh.php

I never used ksh much, but that's what it looks like to me. I think the $ is just the symbol to access the data in a variable. Try it out and see. Like, type some commands you know won't work and then type "echo $?" to see what it returns. If the command is successful, it looks like it's always returning 0. Good luck!

2006-08-10 17:12:57 · answer #1 · answered by anonymous 7 · 0 1

Just confirming the post above. $? in shells derived from the classic Bourne shell refers to the exit status of the previous command. Nice programs will return some other status if they fail, giving you a way to test it in the script.

2006-08-10 17:45:36 · answer #2 · answered by Ken H 4 · 1 0

You might find the answer here:

Runtime Errors and others:
http://support.microsoft.com/default.aspx?scid=kb;en-us;255058

Good Luck

2006-08-10 16:55:02 · answer #3 · answered by phy333 6 · 0 2

fedest.com, questions and answers