Skip to content

Commit d4d4738

Browse files
committed
Fix undefined variable during startup
1 parent d64670a commit d4d4738

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

watcherd

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ MY_DATE="2022-12-17"
2929
MY_URL="https://github.com/devilbox/watcherd"
3030
MY_AUTHOR="cytopia <[email protected]>"
3131
MY_GPGKEY="0xA02C56F0"
32-
MY_VERSION="1.0.5"
32+
MY_VERSION="1.0.6"
3333
MY_LICENSE="MIT"
3434

3535
# Default settings
@@ -174,54 +174,78 @@ while [ $# -gt 0 ]; do
174174
case "${1}" in
175175
-p)
176176
shift
177+
if [ -z "${1:-}" ]; then
178+
>&2 echo "${MY_NAME}: -p requires an argument."
179+
exit 1
180+
fi
177181
if [ ! -d "${1}" ]; then
178-
>&2 echo "Specified directory with -p does not exist: '${1}'."
182+
>&2 echo "${MY_NAME}: Specified directory with -p does not exist: '${1}'."
179183
exit 1
180184
fi
181185
WATCH_DIR="${1}"
182186
;;
183187
-a)
184188
shift
189+
if [ -z "${1:-}" ]; then
190+
>&2 echo "${MY_NAME}: -a requires an argument."
191+
exit 1
192+
fi
185193
if [ "${1:0:1}" = "-" ]; then
186-
>&2 echo "Specified add command cannot start with '-': '${1}'."
194+
>&2 echo "${MY_NAME}: Specified add command cannot start with '-': '${1}'."
187195
exit 1
188196
fi
189197
CMD_ADD="${1}"
190198
;;
191199
-d)
192200
shift
201+
if [ -z "${1:-}" ]; then
202+
>&2 echo "${MY_NAME}: -d requires an argument."
203+
exit 1
204+
fi
193205
if [ "${1:0:1}" = "-" ]; then
194-
>&2 echo "Specified del command cannot start with '-': '${1}'."
206+
>&2 echo "${MY_NAME}: Specified del command cannot start with '-': '${1}'."
195207
exit 1
196208
fi
197209
CMD_DEL="${1}"
198210
;;
199211
-t)
200212
shift
213+
if [ -z "${1:-}" ]; then
214+
>&2 echo "${MY_NAME}: -t requires an argument."
215+
exit 1
216+
fi
201217
if [ "${1:0:1}" = "-" ]; then
202-
>&2 echo "Specified trigger command cannot start with '-': '${1}'."
218+
>&2 echo "${MY_NAME}: Specified trigger command cannot start with '-': '${1}'."
203219
exit 1
204220
fi
205221
CMD_TRIGGER="${1}"
206222
;;
207223
-w)
208224
shift
225+
if [ -z "${1:-}" ]; then
226+
>&2 echo "${MY_NAME}: -w requires an argument."
227+
exit 1
228+
fi
209229
if [ "${1}" != "bash" ] && [ "${1}" != "inotify" ]; then
210-
>&2 echo "Specified watcher with -w must either be 'bash; or 'inotify': '${1}'."
230+
>&2 echo "${MY_NAME}: Specified watcher with -w must either be 'bash; or 'inotify': '${1}'."
211231
exit
212232
fi
213233
if [ "${1}" = "inotify" ]; then
214234
if ! command -v inotifywait >/dev/null 2>&1; then
215-
>&2 echo "Specified watcher 'inotify' requires 'inotifywait' binary. Not found."
235+
>&2 echo "${MY_NAME}: Specified watcher 'inotify' requires 'inotifywait' binary. Not found."
216236
exit
217237
fi
218238
fi
219239
WATCHER="${1}"
220240
;;
221241
-i)
222242
shift
243+
if [ -z "${1:-}" ]; then
244+
>&2 echo "${MY_NAME}: -i requires an argument."
245+
exit 1
246+
fi
223247
if ! echo "${1}" | grep -Eq '^[1-9][0-9]*$'; then
224-
>&2 echo "Specified interval with -i is not a valid integer > 0: '${1}'."
248+
>&2 echo "${MY_NAME}: Specified interval with -i is not a valid integer > 0: '${1}'."
225249
exit 1
226250
fi
227251
INTERVAL="${1}"
@@ -238,8 +262,7 @@ while [ $# -gt 0 ]; do
238262
exit 0
239263
;;
240264
*)
241-
echo "Invalid argument: ${1}"
242-
echo "Type '${MY_NAME} --help' for available options."
265+
echo "${MY_NAME}: Invalid argument: ${1}. Type --help for available options."
243266
exit 1
244267
;;
245268
esac
@@ -248,15 +271,15 @@ done
248271

249272
# Make sure required arguments are set
250273
if [ -z "${WATCH_DIR}" ]; then
251-
>&2 echo "Error: -p is required. Type --help for more information."
274+
>&2 echo "${MY_NAME}: Error: -p is required. Type --help for more information."
252275
exit 1
253276
fi
254277
if [ -z "${CMD_ADD}" ]; then
255-
>&2 echo "Error: -a is required. Type --help for more information."
278+
>&2 echo "${MY_NAME}: Error: -a is required. Type --help for more information."
256279
exit 1
257280
fi
258281
if [ -z "${CMD_DEL}" ]; then
259-
>&2 echo "Error: -d is required. Type --help for more information."
282+
>&2 echo "${MY_NAME}: Error: -d is required. Type --help for more information."
260283
exit 1
261284
fi
262285

0 commit comments

Comments
 (0)