0

I have the code bellow which is supposed to check if the 1st argument is anything other than "boot" or "shutdown"

if [[ "$1" != "boot" || "$1" != "shutdown" ]]
then
    echo "foo"
    exit 1
fi

the code looks correct but when I pass it boot, as in $1 = boot, it think that $1 is not equal to boot and print out "foo".

I am very confused and any help is appreciated.

Happy Lad
  • 17
  • 5
  • That condition is always true. – William Pursell Mar 17 '22 at 16:27
  • 1
    If the first argument is `boot`, then it is not `shutdown`. Perhaps you means to use `&&`. – William Pursell Mar 17 '22 at 16:27
  • Totally unrelated, but a pet-peeve of mine. If your script is going to exit non-zero, it should emit an error message. Error messages belong on stderr. `echo "foo" >&2` – William Pursell Mar 17 '22 at 16:28
  • ...not just error messages; _all_ diagnostic information for the user belongs on stderr. So error messages, but also logs and prompts -- anything that isn't output as such. Otherwise that information will end up getting mixed into output redirected through pipelines / into files / etc., and not actually displayed. – Charles Duffy Mar 17 '22 at 16:29
  • oh I think I need more sleep, I see my error now haha – Happy Lad Mar 17 '22 at 16:44

0 Answers0