Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

sh doesn't work ?

Hi, All

I want use shell script , but script does'nt work. It seems '[' character reading fail.

Does anybody have a those things and know about how to fix it?

My problem shell script and results are below.

<div class='quotetop'>QUOTE </div>

--- Quote Start ---

# /bin/sh -xv test# !/bin/sh

if [ $# -ne 2 ]; then

echo wrong.

exit

fi

+[ 0 -ne 2 ]

[: not found[/b]

--- Quote End ---

And Under Fedora linux results are below.

<div class='quotetop'>QUOTE </div>

--- Quote Start ---

# /bin/sh -xv test# !/bin/sh

if [ $# -ne 2 ]; then

echo wrong.

exit

fi

+ &#39;[&#39; 0 -ne 2 &#39;]&#39;+ echo wrong.

wrong.

+ exit[/b]

--- Quote End ---

http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/huh.gif

4 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Try:

    if test $# -ne 2; then

    echo wrong.

    exit

    fi

    It&#39;s an alternate way of writing the same script and while I haven&#39;t tested it under Nios II Linux, I&#39;m reasonably confident it should work.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi, Ken

    Thank you for your reply, But It does&#39;nt work and found another problem.

    first, results for your advice.

    <div class='quotetop'>QUOTE </div>

    --- Quote Start ---

    # cat test# !/bin/sh

    if $# -ne 2 ; then

    echo wrong.

    exit

    fi

    # sh -xv test# !/bin/sh

    if $# -ne 2 ; then

    echo wrong.

    exit

    fi

    +0 -ne 2

    0: not found# [/b]

    --- Quote End ---

    and , Another problem. This seemed that child process couldn&#39;t run or fail and appear login.

    I typeed " a=`echo nios`"

    <div class='quotetop'>QUOTE </div>

    --- Quote Start ---

    # a=`echo nios`

    /etc/issue www.microtronix.com June 2005

    Welcome to Linux on the Nios II

    Nios2 login:[/b]

    --- Quote End ---

    http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/dry.gif
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    /bin/sh is mostly linked to another shell (bash/dash, ...)

    You need to determine what shell you are running on the Nios II (e.g. hush) and see what you are running on your development machine. Only then can you make a fair comparison since not all shell support (obviously) the same syntax set.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I have the same problems as aqura. (I&#39;m using uClinux 1.4.) When you select "sh" for a new "Nios II Linux Filesystem" project, the information there says that it is indeed bash, so aqura&#39;s script is supposed to work.

    I think these features of "sh" might just be broken in this release. If anyone has been able to get them to work, please let me know. Alternatively, if anyone knows of a lightweight shell for Nios II uClinux that has working command substitution (i.e. backquoting), then again please let me know.