This is the code I have:
#!/bin/bash
FILES=~/Desktop/cpp/$1/*
mkdir ~/Desktop/cpp/$1o
for f in $FILES
do
echo $(basename $f) >> ~/Desktop/cpp/$1err.log
g++ '"'$f'"' -std=c++11 -o '"'~/Desktop/cpp/$1o/$(basename "$f").out'"' 2>> ~/Desktop/cpp/$1err.log
done
If I don't use '"' parts, then the script works fine for files without spaces. With them, it says:
usr/bin/ld: cannot open output file /dirname/-
x.out: No such file or directory
How do I add quotation marks around the file name so that spaces are supported?
g++ "$f" -std=c++11 -o "~/Desktop/cpp/$1o/$(basename "$f").out" 2>> ~/Desktop/cpp/$1err.log
– Kazi Siddiqui Oct 03 '20 at 17:47