Question

In Linux or Unix based systems, do every command have return value?

If yes then return value 0 = successful execution and >0 = not successful?

Can I imagine that every command is a like function which accepts some parameters and returns some values?

Was it helpful?

Solution

As far as I'm aware, every program in every major OS returns a value to the caller. You can get at this value by using echo $? in Linux.

And you're correct that 0 generally means success and any other value generally indicates something went wrong. But exact values are program specific and do not have to conform to this norm.

OTHER TIPS

Yes, because that is the case.

int main(int argc, char *argv[]) {
  // returns an int.
}

Or, just do a

/bin/true
echo $?
0
/bin/false
echo $?
1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top