I am trying to iterate over a path to a directory to run a function on all the files. Please note that this is using the Bourne Shell (/bin/sh
) - NOT BASH - as that is part of the requirements I am under.
I have found resources on:
- Prefix/Suffix substitution
- Available with Bourne's parameter expansion
- Bash literals
I cannot at this time get things working. The for
loop executes, but it is using the string version of the basepath
, when I need it to use the literal (hence bash literals ex: ${!parameter}
; but I need it for Bourne).
Currently, I have:
#/bin/sh
PROJECT_NAME="Testing"
build_path=$(pwd | sed "s/${PROJECT_NAME}.*/${PROJECT_NAME}\//")
upload_folder() {
basepath="$1/*"
basepath="${basepath%\"}" # suffix
basepath="${basepath#\"}"
printf "${basepath}"
for entry in ${basepath}; do
echo "Entering ${entry}"
if [ -f "$entry" ]; then
echo "Found a file ${entry}"
# HERE IS WHERE I WOULD RUN ANOTHER FUNCTION
elif [ -d "$entry" ]; then
echo "Going into folder ${entry} to upload"
upload_folder ${entry}
else
echo "Nothing found"
fi
echo "Finished with $entry"
done
}
upload_folder $build_path
I hope I can get some assistance here; really stuck on this one.