Bash shell support?
Juergen Hennerich
juergen at hennerich.eu
Wed Aug 30 22:26:57 UTC 2006
Riaz Rahaman schrieb:
> You are right, my script did have a !/bin/sh in that and when I changed
> that to !/bin/ash it gives the same error on my desktop as well.
>
> the thing with arrays is that I run this script with different command
> and this array is in a loop and can be more than one depending on the
> size. So hard coding would not a be a good idea. or if I prefer hard
> coding the array size then I need to restrict the way the script is used.
>
I haven't said anything about hard coding. You have a complete
programming language. So you can program around the limitations ;-)
I've attached an example of an array hack/implementation for ash.
There are two scripts attached. The first (bash_array_test.sh) is one of
the examples, which I attached to an earlier mail. It creates 10
functions (func_1 to func_10) and puts the function names into an array.
Then it copies the elements from that array in random order into a
second array. Finally it executes the functions in the second array.
The second (ash_array_test.sh) does the same, with a small array
implementation (using variable like array1_1).
With create_array name you can create an array. With name_we you can
write an element into the array. With name_re you can read an element
from the array. _de deletes an element, _ne gives you the number of
elements, _pi prints an index, _pe prints all elements and name_li n
gives you the n'th element in the array. And of course name_destroy
destroys the array.
This is only a quick hack and therefore, the source is a little bit
crude, not completely thought through and not really tested.
Juergen
> thank a lot of the help.
>
> Riaz
>
> On 8/29/06, *Juergen Hennerich* <juergen at hennerich.eu
> <mailto:juergen at hennerich.eu>> wrote:
> Most likely your tests don't run on ash. How do you start your tests?
> Setting your login shell to ash doesn't matter. If you start your script
> with sh scrip_name you are using bash. If you start your script with
> ./script_name and the first line in the script is not "#!/bin/ash", but
> "#!/bin/sh" then you are also using bash. You are only using ash if you
> start the script with ash script_name or change the first line to
> "#!/bin/ash". You can also test for array support if you call start
> your
> ash and type "var[1]=x" for example. If you get an error message, your
> ash does not support arrays.
>
More information about the busybox
mailing list