dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "lunkov@gmail.com" <lunkov@gmail.com>
To: dash@vger.kernel.org
Subject: Maybe a mistake
Date: Fri, 17 Apr 2020 19:37:09 +0300	[thread overview]
Message-ID: <CAGQt5nnH+ZBXbKreCFyEzqed8Yq_P6YqT0ideKVzd7OU_4bTAg@mail.gmail.com> (raw)

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.

             reply	other threads:[~2020-04-17 16:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-17 16:37 lunkov [this message]
2020-04-17 16:51 ` Harald van Dijk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGQt5nnH+ZBXbKreCFyEzqed8Yq_P6YqT0ideKVzd7OU_4bTAg@mail.gmail.com \
    --to=lunkov@gmail.com \
    --cc=dash@vger.kernel.org \
    --subject='Re: Maybe a mistake' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).