要编译我的源目录中的所有C ++文件,我运行
g++ -std=c++17 ../src/*.cpp -o ../out/a.out
除了cpp
之外,如何编译给定目录中的所有main.cpp
文件?
庆典:
shopt -s extglob
g++ -std=c++17 ../src/!(main).cpp -o ../out/a.out
ref:https://www.gnu.org/software/bash/manual/bash.html#Pattern-Matching
for f in $(find /path/to/files -name "*.cpp" ! -name "main.cpp")
do
g++ -std=c++17 path/to/files/"$f" -o /path/to/out/....
done
我们可以将glob过滤成Bash数组:
unset files
for i in ../src/*.cpp
do test "$i" = '../src/main.cpp' || files+=("$i")
done
g++ -std=c++17 "${files[@]}" -o ../out/a.out
或者,using GNU grep
and mapfile
:
mapfile -d $'\0' -t files < <(printf '%s\0' ../src/*.cpp | grep -zv '/main\.cpp$')
g++ -std=c++17 "${files[@]}" -o ../out/a.out