run following shell error on solaris but OK on RedHat, why????

run following shell error on solaris but OK on RedHat, why????

Post by Rick Ng Chi W » Thu, 24 Jul 2003 00:26:53



Dear all,

I run following shell on red hat without any error.
==========================================
foo=1

while [ "$foo" -le 20 ]
do
        echo "Here we go again"
        foo=$(($foo+1))
done

exit 0
==========================================

But, when I run some shell on Solaris 9.
I got following error message:

foo: syntax error at line 6: `foo=$' unexpected

What is the problem??
pls help me.

thanks!

 
 
 

run following shell error on solaris but OK on RedHat, why????

Post by kansl.. » Thu, 24 Jul 2003 00:36:13



Quote:> Dear all,

> I run following shell on red hat without any error.
> ==========================================
> foo=1

> while [ "$foo" -le 20 ]
> do
>        echo "Here we go again"
>        foo=$(($foo+1))
> done

> exit 0
> ==========================================

> But, when I run some shell on Solaris 9.
> I got following error message:

> foo: syntax error at line 6: `foo=$' unexpected

> What is the problem??
> pls help me.

Nu clue, but my machine say this:
bash-2.05$ uname -a
SunOS sun30 5.9 Generic_112233-05 sun4u sparc SUNW,Ultra-30
bash-2.05$ echo $SHELL
/usr/bin/bash
bash-2.05$ foo=1
bash-2.05$ while test $foo -le 5; do echo "next"; foo=$(($foo+1)); done
next
next
next
next
next
bash-2.05$

I replace the [...] by test because otherwise it says:
bash: [1: command not found

Wich shell are you using? On redhat bash is default, on Solaris
you get whatever your sysadmin thinks is cool....

 
 
 

run following shell error on solaris but OK on RedHat, why????

Post by Rich Tee » Thu, 24 Jul 2003 00:57:13



Quote:> Dear all,

> I run following shell on red hat without any error.
> ==========================================
> foo=1

> while [ "$foo" -le 20 ]
> do
>         echo "Here we go again"
>         foo=$(($foo+1))
> done

> exit 0
> ==========================================

> But, when I run some shell on Solaris 9.
> I got following error message:

> foo: syntax error at line 6: `foo=$' unexpected

> What is the problem??

The problem is Linux's sh not being sh - it's bash.  One
the Solaris machine, try putting this as the first line
of the script:

        #!/bin/ksh

This is one of those examples that show that it is usually
better to write code on a non-Linux machine, and port it
to Linux, rather than the other way round.

--
Rich Teer, SCNA, SCSA

President,
Rite Online Inc.

Voice: +1 (250) 979-1638
URL: http://www.rite-online.net

 
 
 

run following shell error on solaris but OK on RedHat, why????

Post by Sonny B » Thu, 24 Jul 2003 11:07:17


I believe you need to specify the shell you're using or execute it by
initiating a sub-shell first, i.e., ksh scriptname.  I don't believe
bourn shell can handle (()) calculation.


> > Dear all,

> > I run following shell on red hat without any error.
> > ==========================================
> > foo=1

> > while [ "$foo" -le 20 ]
> > do
> >         echo "Here we go again"
> >         foo=$(($foo+1))
> > done

> > exit 0
> > ==========================================

> > But, when I run some shell on Solaris 9.
> > I got following error message:

> > foo: syntax error at line 6: `foo=$' unexpected

> > What is the problem??

> The problem is Linux's sh not being sh - it's bash.  One
> the Solaris machine, try putting this as the first line
> of the script:

>    #!/bin/ksh

> This is one of those examples that show that it is usually
> better to write code on a non-Linux machine, and port it
> to Linux, rather than the other way round.

 
 
 

run following shell error on solaris but OK on RedHat, why????

Post by Michael Wa » Fri, 15 Aug 2003 17:43:44




Quote:>Dear all,

>I run following shell on red hat without any error.
>==========================================
>foo=1

>while [ "$foo" -le 20 ]
>do
>        echo "Here we go again"
>        foo=$(($foo+1))
>done

>exit 0
>==========================================

The shell code can be rewritten as follows to be more readable:

==========================================
#!/usr/dt/bin/dtksh

(( foo = 1 ))
while (( foo <= 20 )); do
  echo "Here we go again"
  (( foo++ ))
done

exit 0
==========================================

If your Linux does not have /usr/dt/bin/dtksh, you can download
the RPM and install it:

http://www.unixlabplus.com/linux-rpm/
--

 
 
 

1. Why does the following shell script executes differently than the command prompt


Oh, please don't.  Well, the text/plain is OK, but don't put in that
text/html at the end.

Symlinks.  You're using an automount daemon.  But that doesn't answer
your question.

The probable reason is that $cwd is maintained by csh itself, and
initialized when csh starts.  In the case of the interactive shell, it
started in $HOME, and you did "cd bin", and neither one mentions the
fact that /nfs/machine/usr/me is actually in /tmp_mnt.  But when you
run the script, csh re-initializes $cwd with getcwd() or whatever, and
that call returns the full path, no symlinks.

You can test this: run "csh -f" and see if the new csh "knows" about
/tmp_mnt.

bash has an interesting angle on this: if you cd to a path with
symlink(s) in it, you can get the path either with symlinks (pwd -L) or
without (pwd -P).  This only works because pwd is a bash builtin.

It's often a bad idea to rely on absolute paths (including mount
points) remaining the same across machines.  You're setting yourself up
for writing special cases later....

--
Peter Samuelson
<sampo.creighton.edu ! psamuels>

2. Online Linux User Group

3. Why won't RedHat 7.0 run a binary which worked in RedHat 6.x?

4. ISO image of 2nd FreeBSD4.4 disc and md5sum matching failure

5. OK, Why can I 'make' from X, but not non-x shell

6. Problems with TNT2 and Quake2 ( Almost got it I think )

7. Why won't RedHat 7.0 run a binary which worked in RedHat 6.x?

8. PCTV pro (TV+FM)

9. lilo running is giving the following lines as error..

10. lilo running giving the following error lines....

11. I am with the following error, when i am running lilo...

12. suse vs redhat Why we chose redhat Suses error in sales model

13. Trying to run nohup from Korn shell but getting Bourne shell errors