Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for a shell command in unix that has a non zero output that is uniform across all unix platforms (for example will allways return 1 on a unix system) and also has no (or zero value) output in windows.

I tried (in unix):

sh echo 1

but this returns:

cannot execute binary file


echo 1

would not fit this criteria since it produces an output in windows as well as unix.

share|improve this question

closed as not a real question by Simon Sheehan, Canadian Luke, soandos, 8088, TFM Nov 14 '12 at 4:44

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

uname seems to work on a lot of systems. Example: # uname -> FreeBSD. On another computer: #uname -> Linux – Hennes Nov 4 '12 at 19:32
on windows xp: 'uname' is not recognized as an internal or external command, operable program or batch file. – Ocasta Eshu Nov 4 '12 at 20:02
and strangely enough, my mac returned "Darwin"... haha – Ocasta Eshu Nov 4 '12 at 20:03
It should. See :) – Hennes Nov 4 '12 at 20:03
This seems to ask two different questions. Based on the title of this question. Do you want to test to see if what kind or type of system it is being ran on, or are you trying to get exit codes from commands on Windows like you do on Mac, BSD, Linux, Unix? – vgoff Nov 4 '12 at 20:47

The dir command exists in both Linux and Windows and may be suitable for this. The dir command on windows does set the exit code for scripting. It also has a plus, in that it is a non-destructive command.

On Linux, according to the man pages these error codes are available.

Exit status:
 0  if OK,
 1  if minor problems (e.g., cannot access subdirectory),
 2  if serious trouble (e.g., cannot access command-line argument).
share|improve this answer
Really thanks to Joey for helping me flush this out, as I really went on a tangent. – vgoff Nov 4 '12 at 22:33
I wonder if using the information verifying the system version would help. Write a C++ Program to do 'absolutely nothing but fail' if it is on Windows. And write a portion that will return otherwise. – vgoff Nov 7 '12 at 22:03

Test for the existence of the SYSTEMROOT or SYSTEMDRIVE environment variables to confirm you're on Windows. If you insist on a real belt-and-suspenders approach, parse the value to confirm you find a C: or similar drive letter.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.