Thanks for the script. Though, I already have an existing project with code, except the folder is cluttered with object files and editor backups. So I'm trying to copy all *.h and *.c files to a clean subdirectory (/distr), then zip it upon compiling. Though I don't know how to copy files just based on having a .c or .h. I can do it in the terminal no problem, cp ./*.c ./distr and cp ./*.h ./distr, but that same code wouldn't work in the script.
So pretty much, how do I copy source files in a shell script?
So far this is what I have (and it doesn't work):
Code:
#!/bin/bash
# Remove old source-distribution directory
if [ -e ./distr ]; then
rm -r ./distr
fi
# Make a clean source-distribution directory
mkdir ./distr
# Move source code to distribution directory
cFiles=ls "./*.c"
for i in $cFiles; do
cp $i ./distr
done
hFiles=ls "./*.h"
for i in $hFiles; do
cp $i ./distr
done
ETA: Found out how to do that. Had to feed ls output to grep. Ye gads I'm horrible with shell scripting.
Code:
!/bin/bash
# Distribution folder name
distrFolder="./distr"
# Source code file extension expression (for grep)
extension="\.[ch]$"
# Remove old source-distribution directory
if [ -e "$distrFolder" ]; then
rm -r "$distrFolder"
fi
# Make a clean source-distribution directory
mkdir "./$distrFolder"
# Get source code files from current directory
srcFiles=$(ls | grep "$extension")
# Move source code files to distribution directory
for file in $srcFiles; do
cp "./$file" "$distrFolder"
done