Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I found this if statement in /etc/init/rc-initsys.conf

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

I don't understand the or(||) operation in the eval command. Could you please give me some hint or reference?

Thanks and Best Regards!

share|improve this question

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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