keiki keiki -4 years ago 112
Bash Question

OSTYPE not available in sh(ell) script

Currently I'm setting up a new system using the new Xubuntu trusty tahr.
I'm not very familiar with shell scripting, but I have one which needs the OSTYPE environment variable to determine what to do.

If I call

echo $OSTYPE
in the xfce-terminal I get succesfully
linux-gnu
.

If I call following script I only get an empty line.

#!/bin/sh
echo $OSTYPE


Am I missing something or is it maybe a problem of the new ubuntu?

On another machine of mine it works with that script. But I don't know if something was changed for that, because the system was originally not mine.

Answer Source

The OSTYPE environment variable is not recognized by the original Bourne shell, which is what is being invoked by the first line of your script.

Replace it with:

#!/bin/bash

or

#!/bin/ksh

as appropriate to your setup.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download