I'm trying to write an If condition as function and I'm not sure if this is even possible.
Following case:
File1
if_exit()
{
if $1; then
echo "$2"
exit 1
fi
}
File2
source File1
SUUSER=$(whoami)
if_exit "[ $SUUSER != 'root' ]" "Please run the script as root"
Explanation: I want to write a function, which includes If contitions (short example used here). Then I want to call that function with different things like mentioned above in the code example or:
if_exit "[ $(lsb_release -is) != 'Debian' ] && [ $(lsb_release -cs) != 'stretch' ]" "The script only works with Stretch"
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire