toybox icon indicating copy to clipboard operation
toybox copied to clipboard

Shell `elif` and `else` don't appear to interact correctly

Open ludocode opened this issue 2 years ago • 0 comments

Environment

toybox 0.8.10-89-g2f93b89b62d1 (latest commit as of this writing) Arch Linux

Steps to Reproduce

Run this under toybox sh:

#!/bin/sh
if true; then
    echo "case 1"
elif false; then
    echo "case 2"
else
    echo "case 3"
fi

Expected Behaviour

"case 1" should be printed.

Actual Behaviour

Both "case 1" and "case 3" are printed.

Workarounds

A version without elif works as expected:

#!/bin/sh
if true; then
    echo "case 1"
else
    if false; then
        echo "case 2"
    else
        echo "case 3"
    fi
fi

ludocode avatar Oct 24 '23 02:10 ludocode