Ok I'm pretty new at Bash scripting, but like a nerdjunkie I'm hooked already
However I'm having a strange problem when checking if a file exists, here's some output to explain:
bash-3.00$ echo $dtstamp
bash-3.00$ touch SAPHREPI20090810122309.CSV
bash-3.00$ if [[ -e *$dtstamp??????.CSV ]]; then echo "CSV file exists, removing"; fi
bash-3.00$ ls *$dtstamp??????.CSV
As you can see, the if [[ -e ... ]] can't seem to find the file, however if I ls using the same variables it can! Can anyone explain why this might be happening? Any suggestions would be greatly appreciated!
I have now figured out that the cause seems to be using [[ ]] instead of just . The reason I used double-bracketing was to avoid having to quote a variable containing a directory path with a space character in it in the full version of the script:
if [[ -e $archivepath/*$dtstamp??????.CSV ]];
if [ -e "$archivepath"/*$dtstamp??????.CSV ];
I have reverted to the second method now and that seems to work, but could someone point me in the direction of some more information about the effects of double-bracketing so I can understand why this was happening, please?