#!/bin/bash
source /etc/os-release
export PRETTY_NAME
if
${PRETTY_NAME | cut -c 32} = "(Tumbleweed) (x86_64)" ]]
then
echo "This is Tumbleweed"
else
echo "This is something else"
fi
Not sure if it’s progress, but I’ve also enclosed the entire operation in curley brackets as I described above.
Results in a “Bad substitution” error instead.
Googling that error isn’t helpful, results in solutions that say to explicitly declare bash shebang as you see I’ve already done.
is parameter substitution where … is the parameter. Thus … must be the name of a parameter.
Now, PRETTY_NAME might be a parameter, but PRETTY_NAME | cut -c 32 is definitely not.
And it is even difficult to understand what
PRETTY_NAME | cut -c 32
should be.
PRETTY_NAME is a text string
cut -c 32 is a command
and | is a pipe.
Now a pipe can be put between two commands to pipe the standard output of the first command to the standard input of the next command. But there is no first command, only a string.
It could be that you want to have:
$(echo ${PRETTY_NAME} | cut -c 32)
That would output the value of PRETTY_NAME to standard out, which will be read by cut from it’s standard input. Then cut would do something with it (-c 32) and output something to it’s standard output. This string will then be put on the spot (because of the $(…) ).
Then you would have a left string in the comparrison, which will be compaired for equalness (=) with the right string.
But I have no idea if that is what you want. That is always the problem when people ask: is this command correct? Correct for doing what? When that is unknown, only the syntax can be checked.
Ummm…
All really good stuff to understand why some of the test code didn’t work, thx. I realized more or less where the problems were but couldn’t identify them clearly enough to be able to come up with a solution.
Yes, didn’t actually state the main objective in the beginning which is to determine the openSUSE version programmatically.
More specifically, my specific situation needs to only differentiate whether an openSUSE is running TW or “not TW.”
At first, I assumed that would be possible by reading VERSION_ID so asked about that because it’s been a reliable variable in the past for all the stable openSUSE releases not realizing that with Tumbleweed the convention is significantly different… With TW every update defines a new complete version so any program that uses VERSION_ID expires approximately daily.
So, to satisfy the main objective as defined above and work for more than a day (actually the next “zypper up”) the essential static part of the string (exclude the id based on date) that identifies Tumbleweed in general must be extracted from one of the returned strings.
I suppose in retrospect it might also have been possible but not as elegant to test for every known stable openSUSE version since then VERSION_ID is a reliable indicator and then declare anything that doesn’t match would be guessed to be TW. But, aside from being inelegant it opens the door for some new fail in the future if some time another version number doesn’t match.
I’m pretty sure that the Tumbleweed VERSION_ID is always an 8-digit number, in the form YYYYMMDD. I don’t think any other opensuse version uses that format.
No. I have used that, because I have used that so for assignments in scripting (without echo).
You are right. You don’t need $(command) in the shell. But it is very practical for longer commands in scripting.