dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Maybe a mistake
@ 2020-04-17 16:37 lunkov
  2020-04-17 16:51 ` Harald van Dijk
  0 siblings, 1 reply; 2+ messages in thread
From: lunkov @ 2020-04-17 16:37 UTC (permalink / raw)
  To: dash

Hello! I encountered a script execution error using dash. Other shells
execute this script without error. Perhaps there is an error in dash.
Please execute my script in dash and in bash, for example.
-------------------------------------------------------------------------------------------------
#!/bin/dash

DATA='
1
2
${var}
4
5'

test1()
{
    local PATTERN='${var}'

    echo ${DATA} | while read i; do
        F=`echo "${i}" | grep "${PATTERN}"`
        if [ "$F" ]; then
            echo "FOUND"
            break
        fi
    done
}

test2()
{
    local PATTERN='${var}'

    echo ${DATA} | while read i; do
        local F=`echo "${i}" | grep "${PATTERN}"`        # local
        if [ "$F" ]; then
            echo "FOUND"
            break
        fi
    done
}

test3()
{
    local PATTERN='${var}'

    echo "${DATA}" | while read i; do                # quotes
        local F=`echo "${i}" | grep "${PATTERN}"`        # local
        if [ "$F" ]; then
            echo "FOUND"
            break
        fi
    done
}

echo "test1"
test1

echo "test2"
test2    # Only in dash: ./test.sh: 28: local: 2: bad variable name

echo "test3"
test3
-------------------------------------------------------------------------------------------------

Best regards.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-17 16:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-17 16:37 Maybe a mistake lunkov
2020-04-17 16:51 ` Harald van Dijk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).