Testa om variabel är satt

From Linuxwiki
Revision as of 21:53, 11 May 2026 by Linadmin (talk | contribs) (2 revisions imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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