Hello CosmicAlien,
Welcome here.
First I want to mention a feature here on the forums that is not automaticaly or easy to be found by first posters like you: the CODE tags. When evr you post computer text, please copy/paste it between CODE tags. You get the CODE tags by clicking on the # button in the tool bar of the posteditor. It will preserve the layout as it is on your terminal amongst other things. Something that is specialy important when we want to see the white space in statements.
Then you should be a bit more talkative about what you want to achieve. Maybe you should keep in mind: do not describe the step, but the goal.
You talk about using
henk@boven:~> zypper -list-updates
Unknown option 'l'
Unknown option 'i'
henk@boven:~> zypper -lu
Unknown option 'l'
Unknown option 'u'
henk@boven:~
As you see both statements are not doing something very usefull. Thus first checking what zypper statement you need for whatever your goal is, using:
man zypper
as Jim advises would be good.
I was curious and found:
list-updates (lu) [options]
List available updates.
It seems that the - sign you put at the start is of your own invention
From the man page of bash:
if list; then list; elif list; then list; ] … else list; ] fi
The if list is executed. If its exit status is zero, the then list is executed. Otherwise, each elif list is executed in turn, and if its exit status is zero, the corresponding then list is executed and the command completes. Otherwise, the else list is executed, if present. The exit status is the exit status of the last command executed, or zero if no condition tested true.
So after the “if” you need a “list”. You used the list
[zypper -lu == "no updates"]
That looks like a test or statement:
test expr
expr ]
Return a status of 0 or 1 depending on the evaluation of the conditional expression expr. Each operator and operand must be a separate argument. Expressions are composed of the primaries described above under CONDITIONALEXPRESSIONS. test does not accept any options, nor does it accept and ignore an argument of – as signifying the end of options.
And thus there must be a conditional expression between the … ].
The == lets us assume that you want to compare two strings. But left of the == there are two strings because of the white space between zypper and -lu. And even when you would make the syntax correct by putting e.g. " " around those two words, you are then still comparing two strings. I can tell you the outcome “zypper -lu” is never equal to “no updates”.
You should not use “zypper list-updates” as a string, you must execute it, catch the output and check it for the string “no-updates”. Something like:
zypper lu | grep -q ‘no updates’
which will return 0 as the string i found in the output.
Then your statements woul be sometyhing like
if zypper lu | grep -q 'no updates'
then echo "No updates"
else echo "Updates"
fi
This is not tested by me. Please look if it helps and come bacl with further questions without forgetting hat man pages ar your friend, specialy when programming.