1

I have a legacy script that depends on the value of $OSTYPE variable. What this script expects is that on Solaris the value is "SunOS" while on AIX it is "AIX". For Linux it checks the variable against the regex where the uppercased value starts with "LINUX".

I've tried to run this script from Jenkins, and discovered that the values are different: Solaris returns "solaris2.11" while AIX returns "aix7.1.0.0". I ran the echo $OSTYPE command on exactly the same servers where Jenkins runs the script, and I get "SunOS"/"AIX" instead.

So the main question I have is: what is the source of this difference (how does the system form the value of this variable, and why does Jenkins have different values than just echo ran from bash). A side question is which is the reliable way to use $OSTYPE.

Dmitry Kuzminov
  • 6,180
  • 6
  • 18
  • 40
  • 1
    This variable is set by Bash. Not in a place where I can examine its history to see whether this was changed and when. – tripleee Dec 05 '19 at 18:59
  • @tripleee I tried to run the `echo $OSTYPE` from bash, sh, other shells available on the Solaris server: everything echoes "SunOS". The Groovy in Solaris uses an `sh` command (is it an 'sh' shell invocation?) I'm curious where does Jenkins take those values from. – Dmitry Kuzminov Dec 05 '19 at 19:11
  • Update: **zsh** returned "solaris2.11" but still returns "aix" on AIX. – Dmitry Kuzminov Dec 05 '19 at 19:18

2 Answers2

6

The most reliable way is to use the command:

uname

with different options. The result you see is only the command uname. If you want more detailed info about version, architecture you can use

uname -a
Romeo Ninov
  • 6,538
  • 1
  • 22
  • 31
4

The variable OSTYPE stores the value of OS TYPE in the shell variables. It depends on shell what value it stores.

For example, if you are using bash, you will get one value of OSTYPE variable, in zsh, some other value and in sh, you may not get any value itself.

See the difference below in using bash and zsh.

bash

$ echo $OSTYPE
  darwin18

zsh

% echo $OSTYPE
  darwin18.0

So, you may need to check what shell jenkins is using when you are getting different values of OSTYPE

Samit
  • 595
  • 2
  • 12
  • That partially answers my question. The echo from **zsh** indeed returned "solaris2.11" on Solaris, however this doesn't explain the issue on AIX: it still returns "aix" being run manually from zsh. Anyway thank you, I'm trying to identify which shell does Jenkins use on AIX. – Dmitry Kuzminov Dec 05 '19 at 19:17
  • I don't have access to any AIX machine to check further. – Samit Dec 05 '19 at 19:19
  • 2
    It would be very weird indeed if Jenkins used zsh, seeing as it has some syntactic differences from POSIX. – tripleee Dec 05 '19 at 19:52