2
rated 0 times
[
2]
[
0]
/ answers: 1 / hits: 2231
/ 2 Years ago, wed, december 29, 2021, 11:14:23
I'd like to use variable as condition in case statement. Something similar to:
#!/bin/sh
ALLOWED_SERVICES=tomcat6|james;
case $1 in
$ALLOWED_SERVICES )
service $1 restart
;;
* )
echo "Unsupported argument"
;;
esac
This doesn't work. When script is started with tomcat6 argument for exapmle, it outpoots "Unsuported argument" message.
But when case condition is hardcoded it works ok:
case $1 in
tomcat6|james )
service $1 restart
;;
* )
echo "Unsupported argument"
;;
esac
Is it possible to use variables in this case?
More From » environment-variables