Here is the bash script:
<code>#!/usr/bin/env bash
# Function to rename the folder
rename_folder() {
exec 3<&0
find . -depth -type d -name "test" | while IFS= read -r dir; do
echo "Rename? [Y/n]"
while true; do
read -r -u3 choice
case "$choice" in
[yY])
echo "choose yes"
break
;;
[nN])
echo "choose no"
exit 0 # Exit function with status 0
;;
*) echo "Please enter 'Y' or 'N'"
;;
esac
done
done
}
rename_folder
echo "when choosen no this line should not be printed"
</code>
<code>#!/usr/bin/env bash
# Function to rename the folder
rename_folder() {
exec 3<&0
find . -depth -type d -name "test" | while IFS= read -r dir; do
echo "Rename? [Y/n]"
while true; do
read -r -u3 choice
case "$choice" in
[yY])
echo "choose yes"
break
;;
[nN])
echo "choose no"
exit 0 # Exit function with status 0
;;
*) echo "Please enter 'Y' or 'N'"
;;
esac
done
done
}
rename_folder
echo "when choosen no this line should not be printed"
</code>
#!/usr/bin/env bash
# Function to rename the folder
rename_folder() {
exec 3<&0
find . -depth -type d -name "test" | while IFS= read -r dir; do
echo "Rename? [Y/n]"
while true; do
read -r -u3 choice
case "$choice" in
[yY])
echo "choose yes"
break
;;
[nN])
echo "choose no"
exit 0 # Exit function with status 0
;;
*) echo "Please enter 'Y' or 'N'"
;;
esac
done
done
}
rename_folder
echo "when choosen no this line should not be printed"
even if i press n/N, it prints “when choosen no this line should not be printed”.
When pressed n/N, i would like to exit the script completely.
What can be done here?