Hi,
Can you please help. I am scripting in sh and I am trying to simply copy one directory to another but for some reason my variables are not recognised?
echo "The latest version of the program is being found......."
cd $SOFTWARE/src/$progname
version=`ls $SOFTWARE/src/$progname | grep 'v00*' | tail -1`
echo "Latest version for $progname is $version"
#Copy over the latest version of the program
cp -r $SOFTWARE/src/$progname/$version $SOFTWARE/devl/$progname
The problem is to do with the $version variable it seems because when I subsitute $version with a directory name that is hard coded it works BUT when you simply echo $version it also looks correct. Do I need to convert it to a different format or something?
I think cabrao meant that you didn't need the . Besides, with your grep in single quotes the shell would not expand it in any way so it would look for filenames literally including v00
At the very least in a regular expression you would need .* (without single quotes)
A * in a regular expression matches 0 or more of the last expression (in your case the character 0), whereas . means match any character and .* matches 0 or more of any character.
okay, these alternatives still work but i am facec with the same problem when trying to do the copy, it seems to find the latest directory or version e.g. v003 but it does not copy the directory to the target directory?
if i hard code v003 in the scrpt instead it works though???
don't get any I'm affraid, i only realise it hasn't copied the directory when looking into the target one and its empty. to confirm the source and target are correct I have echoed these pathnames and they appear correct in the terminal and when I do the same command cp -r source target on the command line it works? by the way I'm on the linux too
tried this too but still nothing, its strange, I have even echoed each variable to a file just to check for spaces but nothing!! One thing I have noticed though it if I manually created a folder in the target directory when I run this script it deletes this folder almost suggesting the $version variable is in fact empty but when I echo this it shows the correct value!?!?!!?
The same code working fine for me for an example which i tried ...have to investigate but don't have access to your system to see what is really happening ..