Maybe a mistake

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux