Re: Bash scripting -- Usage of arrays

2005-11-30 Thread Jayesh Jayan
Hi Marco,

Yes you are correct. It is as you have given :)

Thank you.


On 11/30/05, Marco Gigante [EMAIL PROTECTED] wrote:

 On Wed, Nov 30, 2005 at 02:39:15AM +0530, Jayesh Jayan wrote:
  Hi,
 
  Today I was trying to script using arrays in FreeBSD 5.4 but it doesn't
  work.
 
  Below is a sample script which I used.
 
  **
 
  #!/bin/bash
 
  array=( zero one two three four);
  echo Elements in array0:  [EMAIL PROTECTED]
 
  **
 
  It works fine on RedHat server.
 
  Below is the output.
 
  # sh array.sh
  Elements in array0:  zero one two three four
 
  Below is the out put from the FreeBSD server using the same code.
 
  -bash-2.05b# sh aa.sh
  aa.sh: 3: Syntax error: word unexpected (expecting ))

 You should use: bash array.sh
 On FreeBSD sh != bash

 $ ls -l `which sh`
 -r-xr-xr-x  1 root  wheel  763316 Sep  3 08:37 /bin/sh
 $ ls -l `which bash`
 -rwxr-xr-x  2 root  wheel  471136 Jun 12 01:13 /usr/local/bin/bash

 Cheers

 --
 Marco Gigante




--
Jayesh Jayan

The box said Requires Windows 95, NT, or better, so I installed Linux.

Visit my homepage @ http://www.jayeshjayan.com
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Bash scripting -- Usage of arrays

2005-11-29 Thread Jayesh Jayan
Hi,

Today I was trying to script using arrays in FreeBSD 5.4 but it doesn't
work.

Below is a sample script which I used.

**

#!/bin/bash

array=( zero one two three four);
echo Elements in array0:  [EMAIL PROTECTED]

**

It works fine on RedHat server.

Below is the output.

# sh array.sh
Elements in array0:  zero one two three four

Below is the out put from the FreeBSD server using the same code.

-bash-2.05b# sh aa.sh
aa.sh: 3: Syntax error: word unexpected (expecting ))

Please guide me on how to use arrays on freebsd too.

--

Jayesh Jayan

The box said Requires Windows 95, NT, or better, so I installed Linux.

Visit my homepage @ http://www.jayeshjayan.com
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Bash scripting -- Usage of arrays

2005-11-29 Thread Wesley Shields
On Wed, Nov 30, 2005 at 02:39:15AM +0530, Jayesh Jayan wrote:
 Hi,
 
 Today I was trying to script using arrays in FreeBSD 5.4 but it doesn't
 work.
 
 Below is a sample script which I used.
 
 **
 
 #!/bin/bash
 
 array=( zero one two three four);
 echo Elements in array0:  [EMAIL PROTECTED]
 
 **
 
 It works fine on RedHat server.
 
 Below is the output.
 
 # sh array.sh
 Elements in array0:  zero one two three four
 
 Below is the out put from the FreeBSD server using the same code.
 
 -bash-2.05b# sh aa.sh
 aa.sh: 3: Syntax error: word unexpected (expecting ))
 
 Please guide me on how to use arrays on freebsd too.

Bash (installed via ports) is in /usr/local/bin.  Change the first line
to be #!/usr/local/bin/bash and chmod 750 (at least) the script.  This
way you can just ./aa.sh and be done.

If you prefer to run it as you have shown above don't run sh aa.sh,
instead do bash aa.sh, assuming bash is in your path.  sh aa.sh will try
and run the script through sh (which is not bash).

[EMAIL PROTECTED] ~  ls -la foo.sh
-rwxr-xr-x  1 wxs  wxs  97 Nov 29 16:26 foo.sh*
[EMAIL PROTECTED] ~  cat foo.sh
#!/usr/local/bin/bash

array=( zero one two three four);
echo Elements in array0:  [EMAIL PROTECTED]
[EMAIL PROTECTED] ~  bash ./foo.sh
Elements in array0:  zero one two three four
[EMAIL PROTECTED] ~  ./foo.sh
Elements in array0:  zero one two three four
[EMAIL PROTECTED] ~  sh ./foo.sh
./foo.sh: 3: Syntax error: word unexpected (expecting ))
[EMAIL PROTECTED] ~ 

-- WXS
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Bash scripting -- Usage of arrays

2005-11-29 Thread John-Mark Gurney
Jayesh Jayan wrote this message on Wed, Nov 30, 2005 at 02:39 +0530:
 Below is the output.
 
 # sh array.sh

Install the bash port (as root: pkg_add -r bas), and then try again
using bash...

FreeBSD doesn't have bash installed by default (and hence, /bin/sh is
not bash like it is usually on Linux), and our sh doesn't have that
feature...

-- 
  John-Mark Gurney  Voice: +1 415 225 5579

 All that I will do, has been done, All that I have, has not.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Bash scripting -- Usage of arrays

2005-11-29 Thread John Baldwin
On Tuesday 29 November 2005 04:09 pm, Jayesh Jayan wrote:
 Hi,

 Today I was trying to script using arrays in FreeBSD 5.4 but it doesn't
 work.

 Below is a sample script which I used.

 **

 #!/bin/bash

 array=( zero one two three four);
 echo Elements in array0:  [EMAIL PROTECTED]

 **

 It works fine on RedHat server.

 Below is the output.

 # sh array.sh
 Elements in array0:  zero one two three four

 Below is the out put from the FreeBSD server using the same code.

 -bash-2.05b# sh aa.sh
 aa.sh: 3: Syntax error: word unexpected (expecting ))

 Please guide me on how to use arrays on freebsd too.

sh != bash

You can either install bash from ports, or you can write your scripts in sh 
without using bash extensions.  For example, with sh you can do things like:

array=zero one to three four
for x in $array; do
echo $x
done

However, you can't easily get the count of items.  You could maybe do 
something like:

set $array
echo $# items

but that's somewhat hackish.

-- 
John Baldwin [EMAIL PROTECTED]http://www.FreeBSD.org/~jhb/
Power Users Use the Power to Serve  =  http://www.FreeBSD.org
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Bash scripting -- Usage of arrays

2005-11-29 Thread Jayesh Jayan
Hi Wesley,

Thank you.

I understood it completely.

The explanation was great.

Thank you once again.


On 11/30/05, Wesley Shields [EMAIL PROTECTED] wrote:

 On Wed, Nov 30, 2005 at 02:39:15AM +0530, Jayesh Jayan wrote:
  Hi,
 
  Today I was trying to script using arrays in FreeBSD 5.4 but it doesn't
  work.
 
  Below is a sample script which I used.
 
  **
 
  #!/bin/bash
 
  array=( zero one two three four);
  echo Elements in array0:  [EMAIL PROTECTED]
 
  **
 
  It works fine on RedHat server.
 
  Below is the output.
 
  # sh array.sh
  Elements in array0:  zero one two three four
 
  Below is the out put from the FreeBSD server using the same code.
 
  -bash-2.05b# sh aa.sh
  aa.sh: 3: Syntax error: word unexpected (expecting ))
 
  Please guide me on how to use arrays on freebsd too.

 Bash (installed via ports) is in /usr/local/bin.  Change the first line
 to be #!/usr/local/bin/bash and chmod 750 (at least) the script.  This
 way you can just ./aa.sh and be done.

 If you prefer to run it as you have shown above don't run sh aa.sh,
 instead do bash aa.sh, assuming bash is in your path.  sh aa.sh will try
 and run the script through sh (which is not bash).

 [EMAIL PROTECTED] ~  ls -la foo.sh
 -rwxr-xr-x  1 wxs  wxs  97 Nov 29 16:26 foo.sh*
 [EMAIL PROTECTED] ~  cat foo.sh
 #!/usr/local/bin/bash

 array=( zero one two three four);
 echo Elements in array0:  [EMAIL PROTECTED]
 [EMAIL PROTECTED] ~  bash ./foo.sh
 Elements in array0:  zero one two three four
 [EMAIL PROTECTED] ~  ./foo.sh
 Elements in array0:  zero one two three four
 [EMAIL PROTECTED] ~  sh ./foo.sh
 ./foo.sh: 3: Syntax error: word unexpected (expecting ))
 [EMAIL PROTECTED] ~ 

 -- WXS




--
Jayesh Jayan

The box said Requires Windows 95, NT, or better, so I installed Linux.

Visit my homepage @ http://www.jayeshjayan.com
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Bash scripting -- Usage of arrays

2005-11-29 Thread Jayesh Jayan
Hi John,

I already have bash installed from ports. It is bash 2.05b.



On 11/30/05, John-Mark Gurney [EMAIL PROTECTED] wrote:

 Jayesh Jayan wrote this message on Wed, Nov 30, 2005 at 02:39 +0530:
  Below is the output.
 
  # sh array.sh

 Install the bash port (as root: pkg_add -r bas), and then try again
 using bash...

 FreeBSD doesn't have bash installed by default (and hence, /bin/sh is
 not bash like it is usually on Linux), and our sh doesn't have that
 feature...

 --
   John-Mark Gurney  Voice: +1 415 225 5579

  All that I will do, has been done, All that I have, has not.




--
Jayesh Jayan

The box said Requires Windows 95, NT, or better, so I installed Linux.

Visit my homepage @ http://www.jayeshjayan.com
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Bash scripting -- Usage of arrays

2005-11-29 Thread Jayesh Jayan
Hi John,

Thank you.

It seems to work like a charm.


On 11/30/05, John Baldwin [EMAIL PROTECTED] wrote:

 On Tuesday 29 November 2005 04:09 pm, Jayesh Jayan wrote:
  Hi,
 
  Today I was trying to script using arrays in FreeBSD 5.4 but it doesn't
  work.
 
  Below is a sample script which I used.
 
  **
 
  #!/bin/bash
 
  array=( zero one two three four);
  echo Elements in array0:  [EMAIL PROTECTED]
 
  **
 
  It works fine on RedHat server.
 
  Below is the output.
 
  # sh array.sh
  Elements in array0:  zero one two three four
 
  Below is the out put from the FreeBSD server using the same code.
 
  -bash-2.05b# sh aa.sh
  aa.sh: 3: Syntax error: word unexpected (expecting ))
 
  Please guide me on how to use arrays on freebsd too.

 sh != bash

 You can either install bash from ports, or you can write your scripts in
 sh
 without using bash extensions.  For example, with sh you can do things
 like:

 array=zero one to three four
 for x in $array; do
 echo $x
 done

 However, you can't easily get the count of items.  You could maybe do
 something like:

 set $array
 echo $# items

 but that's somewhat hackish.

 --
 John Baldwin [EMAIL PROTECTED]http://www.FreeBSD.org/~jhb/
 Power Users Use the Power to Serve  =  http://www.FreeBSD.org




--
Jayesh Jayan

The box said Requires Windows 95, NT, or better, so I installed Linux.

Visit my homepage @ http://www.jayeshjayan.com
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Bash scripting -- Usage of arrays

2005-11-29 Thread John-Mark Gurney
Jayesh Jayan wrote this message on Wed, Nov 30, 2005 at 03:19 +0530:
 I already have bash installed from ports. It is bash 2.05b.

But below you were running sh, and not bash...  if you do sh array.sh,
it will not reinterpet the #!/bin/bash line, and re-exec it with the
program in part because /bin/bash doesn't exist on the system, as bash
is installed in /usr/local/bin/bash...

Please try with:
bash array.sh
instead, and see if that works..

 On 11/30/05, John-Mark Gurney [EMAIL PROTECTED] wrote:
 
  Jayesh Jayan wrote this message on Wed, Nov 30, 2005 at 02:39 +0530:
   Below is the output.
  
   # sh array.sh
 
  Install the bash port (as root: pkg_add -r bas), and then try again
  using bash...
 
  FreeBSD doesn't have bash installed by default (and hence, /bin/sh is
  not bash like it is usually on Linux), and our sh doesn't have that
  feature...

-- 
  John-Mark Gurney  Voice: +1 415 225 5579

 All that I will do, has been done, All that I have, has not.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Bash scripting -- Usage of arrays

2005-11-29 Thread Jayesh Jayan
Hi John,

yes it works when executed with bash aa.sh.

Thank you :)

On 11/30/05, John-Mark Gurney [EMAIL PROTECTED] wrote:

 Jayesh Jayan wrote this message on Wed, Nov 30, 2005 at 03:19 +0530:
  I already have bash installed from ports. It is bash 2.05b.

 But below you were running sh, and not bash...  if you do sh array.sh,
 it will not reinterpet the #!/bin/bash line, and re-exec it with the
 program in part because /bin/bash doesn't exist on the system, as bash
 is installed in /usr/local/bin/bash...

 Please try with:
 bash array.sh
 instead, and see if that works..

  On 11/30/05, John-Mark Gurney [EMAIL PROTECTED] wrote:
  
   Jayesh Jayan wrote this message on Wed, Nov 30, 2005 at 02:39 +0530:
Below is the output.
   
# sh array.sh
  
   Install the bash port (as root: pkg_add -r bas), and then try again
   using bash...
  
   FreeBSD doesn't have bash installed by default (and hence, /bin/sh is
   not bash like it is usually on Linux), and our sh doesn't have that
   feature...

 --
   John-Mark Gurney  Voice: +1 415 225 5579

  All that I will do, has been done, All that I have, has not.




--
Jayesh Jayan

The box said Requires Windows 95, NT, or better, so I installed Linux.

Visit my homepage @ http://www.jayeshjayan.com
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Bash scripting -- Usage of arrays

2005-11-29 Thread John Baldwin
On Tuesday 29 November 2005 04:49 pm, Jayesh Jayan wrote:
 Hi John,

 I already have bash installed from ports. It is bash 2.05b.

Then use 'bash foo.sh' :)

-- 
John Baldwin [EMAIL PROTECTED]http://www.FreeBSD.org/~jhb/
Power Users Use the Power to Serve  =  http://www.FreeBSD.org
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Bash scripting -- Usage of arrays

2005-11-29 Thread Marco Gigante
On Wed, Nov 30, 2005 at 02:39:15AM +0530, Jayesh Jayan wrote:
 Hi,
 
 Today I was trying to script using arrays in FreeBSD 5.4 but it doesn't
 work.
 
 Below is a sample script which I used.
 
 **
 
 #!/bin/bash
 
 array=( zero one two three four);
 echo Elements in array0:  [EMAIL PROTECTED]
 
 **
 
 It works fine on RedHat server.
 
 Below is the output.
 
 # sh array.sh
 Elements in array0:  zero one two three four
 
 Below is the out put from the FreeBSD server using the same code.
 
 -bash-2.05b# sh aa.sh
 aa.sh: 3: Syntax error: word unexpected (expecting ))

You should use: bash array.sh
On FreeBSD sh != bash

$ ls -l `which sh`
-r-xr-xr-x  1 root  wheel  763316 Sep  3 08:37 /bin/sh
$ ls -l `which bash`
-rwxr-xr-x  2 root  wheel  471136 Jun 12 01:13 /usr/local/bin/bash

Cheers

-- 
Marco Gigante
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]