[olug] bash script help
William E. Kempf
williamkempf at hotmail.com
Thu Oct 3 19:40:59 UTC 2002
----- Original Message -----
From: "Nick Walter" <waltern at iivip.com>
> I had to make two changes to your script to make it work on my system
> (Red Hat 8.0, bash 2.05b)
>
> First, I changed
>
> let idx=$#-1
>
> to
>
> let idx=$#
Hmmm... either produces the same results for this simplistic example, but
yours works for more complex examples. Guess this doesn't do exactly what I
thought it did.
> and also changed
>
> set "${@:0:$idx} new-value"
>
> to
>
> set "\"${@:0:$idx}\" new-value"
Still not quite right. Here's the full test script I'm using to illustrate:
#! /bin/bash
function doit()
{
let idx=$#
set "\"${@:0:$idx}\" new-value"
echo "$@"
}
doit "foo bar" widget
doit one "two three" four
This produces the following results:
"foo bar" new-value
"one two three" new-value
If this is to be passed on to the next command the results would instead
have to be:
"foo bar" new-value
one "two three" new-value
So there's still some quoting issues.
Bill Kempf
More information about the OLUG
mailing list