I found this shell script($1
,$2
are directories):
mv "$2" "$1" || exit # Make $2 a subdirectory of $1
cd "$1/$(basename "$2")" || exit # Change directories for simplicity
for f in *; do
mv "$f" "${f%.*}.txt" # Add or change the extension
done
it moves the second directory in the first one (so the second directory becomes a subdirectory of the first one) and all the files from the second directory will have a ".txt" extension. I can't figure out why cd "$1/$2"
won't work doesn't basename strip the filename from a given directory? Could someone explain how this part:
cd "$1/$(basename "$2")"
works? Also $2 needs to be in separate quotes("$2"
) because of basename?