Need bash script Help

  • From: "Donald Marang" <donald.marang@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Sat, 24 Jul 2010 19:31:39 -0400

I hope there is someone here with a little experience with functions in a bash 
script.  I wrote a function that will append a filename to a list of filenames. 
 The first argument passed is the name of the variable for a list of filenames. 
 I fashoned this method based on a bash tutorial on how to return values from a 
function.  that use this method and the 'eval' statements within the if 
statement.  Since bash functions can not returna string, passing just the name 
seems to be a poor man's way to call by reference.  The second argument is a 
filename that will be appended to the lisst.  

I think everything is in order except the line below:  
eval _ResultString="'$1'"

I need _ResultString to contain the actual filenames in the variable name in 
the variable whose name is the first argument.  For some reason I can not get 
this statement correct.  

Can anybody know how this assignment statement should look?  


Here's the function:  
AddFilenameToString() {
# $1 is the variable name of the sttring of filenames
# $2 is the new filename to Add
local _ResultName="$1"
local _ResultString=""
eval _ResultString="'$1'"
echo "variable name = $_ResultName"
echo "value = $_ResultString"
if [[ -z "$_ResultString" ]]; then
  echo "create new string"
  eval $_ResultName="'$2'"
else
  echo "append to string"
  eval $_ResultName="'${_ResultString}${IFS}$2'"
fi
}

Don Marang

Other related posts: