чување 8d0200981789ce32c33b866a9d2ebb82d56b8699
родитељ 831f2837b9907211e539f60813016394218fc95c
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Thu, 21 Jul 2022 23:00:21 +0200
Fix empty parameter detection
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 1, додавања: 13(+), брисања: 8(-)
diff --git a/bin/service b/bin/service
@@ -49,7 +49,7 @@ doservice()
msg serv "Service %s activated?\t\t\t" ${service##*/}
svc -ad "${service}" 2>/dev/null
fi;;
- a*) if [ $# -lt 2 ]; then
+ a*) if [ -z "${service}" ]; then
nooutcome=1
msg err "No service given"
exit 2
@@ -57,7 +57,7 @@ doservice()
msg serv "Activating %s\t\t\t" ${service##*/}
svc -a "${service}" 2>/dev/null
fi;;
- d*) if [ $# -lt 2 ]; then
+ d*) if [ -z "${service}" ]; then
nooutcome=1
msg err "No service given"
exit 2
@@ -65,7 +65,7 @@ doservice()
msg serv "Deactivating %s\t\t\t" ${service##*/}
svc -d "${service}" 2>/dev/null
fi;;
- e*) if [ $# -lt 2 ]; then
+ e*) if [ -z "${service}" ]; then
nooutcome=1
msg err "No service given"
exit 2
@@ -76,7 +76,7 @@ doservice()
fi;;
l*) nooutcome=1
svc -l;;
- sta*) if [ $# -lt 2 ]; then
+ sta*) if [ -z "${service}" ]; then
nooutcome=1
msg err "No service given"
exit 2
@@ -84,7 +84,7 @@ doservice()
msg serv "Starting %s\t\t\t" ${service##*/}
svc -s "${service}" 2>/dev/null
fi;;
- sto*) if [ $# -lt 2 ]; then
+ sto*) if [ -z "${service}" ]; then
nooutcome=1
msg err "No service given"
exit 2
@@ -93,7 +93,7 @@ doservice()
msg serv "Stopping %s\t\t\t" ${service##*/}
svc -k "${service}" 2>/dev/null
fi;;
- r*) if [ $# -lt 2 ]; then
+ r*) if [ -z "${service}" ]; then
nooutcome=1
msg err "No service given"
exit 2
@@ -102,8 +102,13 @@ doservice()
svc -r "${service}" 2>/dev/null
fi;;
*) nooutcome=1
- msg err "What to do with %s?" ${service##*/}
- exit 3;;
+ if [ -z "${service}" ]; then
+ msg err "No service given"
+ exit 2
+ else
+ msg err "What to do with %s?" ${service##*/}
+ exit 2
+ fi;;
esac
errno=$?
if [ "${nooutcome}" -eq 1 ]; then