bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Array Elements with Spaces


From: Michael Potter
Subject: Array Elements with Spaces
Date: Sat, 10 Nov 2007 12:10:21 -0600

Group,

I have having a problem with spaces in individual elements of an array.

The space causes a single element to be seen as multiple elements.

Here is a sample run:

-----------------------------------------------------
address@hidden:~/bin> ./arraywithspace.sh
3.1.17(1)-release
got 6 parms
parm: arg1
parm: arg2
parm: arg
parm: 3
parm: arg
parm: four
address@hidden:~/bin> cat ./arraywithspace.sh
#!/bin/bash

declare -a Arguments=("arg1" "arg2" "arg 3" "arg four")

function countparms
{
   echo "got $# parms"

   while (($# != 0 ))
   do
      echo "parm: $1"
      shift
   done
}

echo $BASH_VERSION

countparms ${Arguments[*]}

------------------------------------------------------

The real problem I am having is using the array as a list of arguments
to a command, maybe something like this:

grep -i mypattern ${FileList[*]}

-- 
potter




reply via email to

[Prev in Thread] Current Thread [Next in Thread]