Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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 found this if statement in /etc/init/rc-initsys.conf

# Check for default runlevel in /etc/inittab
    if [ -r /etc/inittab ]
    eval "$(sed -nre 's/^[^#][^:]*:([0-6sS]):initdefault:.*/DEFAULT_RUNLEVEL="\1";/p' /etc/inittab || true)"

I don't understand the or(||) operation in the eval command.

Could you please give me some hint or reference?

share|improve this question
up vote 3 down vote accepted

If the first command fails, the second gets executed and will return a successful exit code. It ensures that the return value of the entire line (as e.g. in $?) is true (exit code 0).

In general, subsequent commands, or, for actions at the end of a script, its caller, might check for the preceding action's return value to determine how to continue (i.e. error handling).

If you (as script author) don't want to report failure for a command, you can add || true to it to always return a successful return code. Depending on how the entire script is used, a single failing command outside of a condition could even abort execution.

share|improve this answer
And why this command needs to always return true ? Because the script starts with "set -e" which tell Bash to exit on any command returning false – Gregory MOUSSAT Jun 9 '12 at 17:17
That would be a reason – simple defensive programming @gre – slhck Jun 9 '12 at 17:18
@GregoryMOUSSAT That's what I meant in the last sentence. The command is allowed to fail without script abortion. – Daniel Beck Jun 9 '12 at 17:18
Thanks. But when will sed fail? In this case, if no DEFAULTLEVEL matched, it will simply exit will empty output. Will it fail in some circumstance? – Summer_More_More_Tea Jun 11 '12 at 2:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .