Testa om variabel är satt

From Linuxwiki
Jump to navigation Jump to search

Testa om variabel är satt i Bash

Källa: http://www.bo.infn.it/alice/alice-doc/mll-doc/linux/scripts/node5.html

Exempel

verify if the PRINTER environment variable is set

$ cat ~/tools/exsh/isset.sh

#!/bin/bash
#
if test "${PRINTER+set}" != set ; then
 echo "$PRINTER is not set"
else
 echo "$PRINTER is set"
fi

Kategori:bash