Afficher un message
Vieux 30/04/2008, 10h06   #4
Janis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: extract array name from string

On 30 Apr., 04:40, Eric <Scor...@gordinator.org> wrote:
> I've got a text file with names like this:
> Variable1[30]
> extraVar22[22]
> Test42Exists[104]
>
> how do i get just the array name in each case
> e.g.:
> N="Variable1[30]"
> echo "$N"|sed <what goes here>"
> or
> echo "$N"|eval match "$N" \(<what goes here>\)"
>
> the output would be Variable1 (dropping the [30])
>
> It can be sed or bash, or whatever, I'm using this in a bash script.
> I was playing with echo 'eval match "$N" \( stuff here \)'
> but i couldnt get it to work right, array names can be a mix of upper and
> lower case, numbers (and possibly underscores).
> Thanks
> Eric


N="Variable1[30]"
echo ${N%%[[]*}


Janis
  Réponse avec citation
 
Page generated in 0,04644 seconds with 9 queries