Please - this is my FIRST ever attempt on scrip and I just want simple answer if possible.
I am modifying existing and working script.
I just want to and more to it so I started with simple insertion of working code into menu.
I am doing OK, but I cannot figure out why I am executing this line of code
esac || whiptail --msgbox "DEBUG ERROR There was an error running option
I understand the "end of case" , but || (or?) does not makes sense to me for now.
I am enclosing PART what I feel is an "problem area"
RET=$?
if [ $RET -eq 1 ]; then
do_finish
elif [ $RET -eq 0 ]; then
if is_pi ; then
case "$FUN" in
1\ *) do_change_pass ;;
2\ *) do_network_menu ;;
3\ *) do_boot_menu ;;
4\ *) do_internationalisation_menu ;;
5\ *) do_interface_menu ;;
6\ *) do_overclock ;;
7\ *) do_advanced_menu ;;
8\ *) do_update ;;
9\ *) do_about ;;
10\ *) do_about ;;
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
esac || whiptail --msgbox "DEBUG ERROR There was an error running option $FU$
else
case "$FUN" in
1\ *) do_change_pass ;;
2\ *) do_network_menu ;;
3\ *) do_boot_menu ;;
4\ *) do_internationalisation_menu ;;
5\ *) do_ssh ;;
I am coding in C/C++ and know about switch / case construct , but I do not understand why duplicating item 9 and inserting it as item 10 is causing this error. It should just run same function as item 9 does.
The "menu" displays OK , but when I select the item 10 I get the DEBUG ERROR message. Is it possible I am getting the "programmer error ..." also but it is getting overridden by the next message?
Help will be much appreciated.
The || is the "control operator" in a bash "OR list". man bash :
So the construct is there to catch errors of case dealing with the various FUN s.
Be aware that $FU$ will expand to just $ (unless FU is defined somewhere in your script).
Try moving the second msgbox to another position to eliminate your "override suspicion"
Does your case work for other inputs, e.g. 3 , or 9 ? What exactly do you enter in either case, and what in the 10 case?
Are you aware that the shown snippet only has some improvement opportunities?
If you are only seeing the DEBUG ERROR message box when you run do_about , it means that do_about is exiting with a non-zero exit code. The exit status of a case statement is the exit status of the last command executed in the command list for the matched pattern or zero if no pattern matched.
The text you included in post #3 in this thread (that Neo edited for you to contain CODE tags) did indeed include the shell script pseudo-code which without CODE tags displays as:
...
esac || if debug
print error code
else
just print the original message
With CODE tags that pseudo-code appears as:
...
esac || if debug
print error code
else
just print the original message
Please use CODE tags when displaying sample input, sample output, and code (or pseudo-code) segments.
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags
```text
and
```
by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
We are very sorry we are being forced to post this.
We did very detailed analysis of our post and resulting discussion based on the original post where we asked for help to resolve simple case command error issue.
On the scale "good , bad and ugly" - forum score is
10% good ( case command returns value )
80 % bad
10 % ugly
The original cause of the error was newer discussed or resolved.
Posting specific about our rating of the one sided discussion would be pointless and
more waste of our time.
We have learned our lesson and would ask to stop sending / posting instructions on how to write and keep our mouth shut so not to disturb this fine forum.