i have an issue with eval and variable assignment.
1) i have a date value in a variable and that date is part of a filename,
var1=20100331
file1=${var1}-D1-0092.xml.zip
file2=${var2}-D2-0092.xml.zip
file3=${var3}-D3-0092.xml.zip
i am passing the above variables to a script via commandline and assigning the values of these
variables to another set of variables using while get opts command as below,
Issue - the array variable FILES is not populated with filenames here.
2) Issue with filenames - I have filenames which consists of spaces and special characters.
eg: REP - inven - 1.TXT
I am using same concept as above. i.e. passing variables to script. i am getting error
with eval command.
Please advise in both scenarios on how to avoid issues.
Thank you very much. First step is working for me.
regarding the step#2, i maintain all the job related variables in a config script which gets evaluated at the start of every job. The below variables are giving error while evaluating,
Thank you. I am able to assign the filenames to a variable now . I have 3 variables like this. all of these are assigned to an array. i am able to get part of the filename (i.e. till the space as a value)while retrieving .
Following is the code :
storing the values in FILES string after we receive the values from commandline,
f) eval FILE=\"\$${OPTARG}\"
FILES="$FILE $FILES";;
assigning the FILES string to an array : set -A filesToGet $FILES
Retrieving each file from the array : file=${filesToGet[$curFileIndex]}
but this way it is considering only part of the filename.i.e. till the first space as a first filename. Please suggest how can i retrive the whole filename i.e. REP00029 - Yesterdays Postings Total_ 1.TXT
Maybe you should directly construct the array like this:
# to add $FILE (string) to $FILES (array)
$FILES[${#FILES[@]}]="$FILE" # ${#FILES[@]} gives the nb of elements in the array => the first empty index (first is 0)
i am passing 3 variables(which contain filenames) to the script and storing these in a string called FILES. Here FILES is not an array.later i am assigning this string FILES to an array using set -A definition. Please advise on how to retrieve the whole filename at once after i assign the FILES string to an array.
print "`date` - Started - Getting $FILES\nremote: $USERHOST:$REMOTEDIR\nlocal: $LOCALDIR\n";
# replace $FILES by ${FILES[*]} (to treat $FILES as an array)
Are all the eval statements really necessary ? (for USERHOST, LOCALDIR ...)
couldn't you proceed as for the first parameter like
This won't work in any way: when you store the various elements in a string you have to separate them somehow so that you can later split the string into array elements. Since you said above that your filenames can contain blanks i am at a loss which delimiter character you want to use.