3
rated 0 times
[
3]
[
0]
/ answers: 1 / hits: 2122
/ 2 Years ago, fri, october 21, 2022, 8:06:26
I am trying to create a nested case statement in which user input is expected (Y/N). However, the system never waits for the input and always goes to the third option, "Please answer yes or no". Can anyone tell me what I am missing?
Here is the case statement
#!/bin/bash
STATUS=status
find /etc/init.d/* -name '*' -print0 | while IFS= read -r -d '' FILE;
do
if [ "$FILE" != "." -o "$FILE" != ".." ]; then
OUTPUT=$($FILE $STATUS)
case "$OUTPUT" in
*disabled* )
echo "Do you wish to start $FILE ?"
read yn
case $yn in
[yY] | [yY][Ee][Ss] )
$FILE start
;;
[nN] | [n|N][O|o] )
;;
* )
echo "Please answer yes or no.";;
esac
;;
* )
echo "App $FILE is running"
;;
esac
fi
done
Running under Ubuntu 14.04 LTS
Sample output
App /etc/init.d/reboot is running
App /etc/init.d/resolvconf is running
App /etc/init.d/rsync is running
App /etc/init.d/rsyslog is running
App /etc/init.d/samba is running
App /etc/init.d/samba-ad-dc is running
Do you wish to start /etc/init.d/saned ?
Please answer yes or no.
More From » bash