Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: unshift





On 2024-04-02 05:41, Dennis Eriksen wrote:


Why not just use 'elif'? :)

shift
while [ "$1" ]; do
    if   [ a ]; then b; c;
    elif [ d ]; then e; f;
    elif [ g ]; then h; i;
    fi
    shift
done

If 'a' matches, the rest of the conditional won't run.

Good idea but in my particular case there's a block of code half way down the loop that applies to everything below it.  I should have shown that in my original.  Or as I have it now:

while [ "$2" ]; do
    shift
    if [ a ]; then b; c; continue fi
    if [ d ]; then e; f; continue fi
    code-applies-to-all-below; more(of-the-same)
    if [ g ]; then h; i; continue fi
    if [ j ]; then k; l; continue fi
done

... so elif won't work.  Yeah,  I should have made that clear from the start, it's what narrows the field of possible solutions.




You could even use 'case'

shift
while [ "$1" ]; do
    case $1 in
        a) b; c;;
        d) e; f;;
        g) h; i;;
    esac
    shift
done

The execution terminates on ';;'.






Messages sorted by: Reverse Date, Date, Thread, Author