Here is a for loop, which is running a regular Whiptail gauge. I this loop, a command might throw an error and I would like to display a message box --msgbox
displaying the error. After that, I could like the script to continue it's way like the error never happened.
Here is an oversimplified code as an example. Here is it's behavior and the code:
- A for list is iterating on an array with 3 numbers and 1 letter.
- For the 2 first numbers, a command using them is executed and a gauge is increasing by 25%.
- For the letter, the command will fail, and I would like to display a
--msgbox
with the error waiting me to press enter - For the last number, the same behavior than for the 2 others.
#!/bin/bash
array=("1" "2" "A" "3")
i=0
for element in "${array[@]}"; do
command $element #This command will fail with any non int value.
echo "XXX"
echo $(expr 100 / 4 \* $i)
echo ${array[$i]}
echo "XXX"
i=$((i+1))
sleep 1
done | whiptail --title "Gauge" --gauge "Wait" 10 80 0
I have already tried few things like command $element || whiptail --title "Exception" --msgbox "Error!" 10 80
. However, as the whiptail for the message box is in the loop for the gauge, the output is broken.
The problem is maybe coming from my design?
Thank you for your help :)