When looping on a folder through a
for f in $path
I am experiencing an unexpected behaviour, i.e. the loops is entered anyway even if no file match the wildcard. I am using cygwin and this is my code
#!/bin/sh
here=$(pwd)
release(){
release="$1"
targetdisk="$2"
package="$3"
searchPath="../$package/${package}Setup/*/*/*.msi"
echo $searchPath
ls $searchPath
for f in $searchPath; do
mode=$(echo $file | sed -e 's:.*/.*/\(.*\)/.*\.msi:\1:')
version=$(echo $file | sed -e 's:.*/\(.*\)/.*/*.\.msi:\1:')
PREVIOUSIFS=$IFS
IFS=#
targetPath="$targetdisk:\\Software and tools\\Install\\$release"
newFile="$targetPath\\$package-$mode-$release.exe"
if [ ! -d "$targetPath" ]; then
mkdir -p "$targetPath"
fi
echo $newFile
echo $f
#cp $file $newFile
IFS=$PREVIOUSIFS
done;
}
release $1 $2 MyStuff
I put on purpose MyStuff, which does not exist:
$ ./release.sh 1.0-dev G
../MyStuff/MyStuffSetup/*/*/*.msi
ls: ../MyStuff/MyStuffSetup/*/*/*.msi: No such file or directory
G:\Software and tools\Install\1.0-dev\MyStuff--1.0-dev.exe
../MyStuff/MyStuffSetup/*/*/*.msi
As you can see however, the two echos are executed. Why this happens even if there is no match?