I'm trying to write a simple Linux make command with bash scripting. here is what I have written so far:
#!/usr/bin/env bash
function make_cmd()
{
read target colon sources
for src in $sources; do
if [ $src -nt $target ]; then
while read cmd && [[ $(echo "$cmd" | grep "$(printf '\t')"*) ]]; do
echo "executing $cmd";
eval ${cmd#$(printf '\t')};
done
break;
fi
done
}
this is the format of input:
target.file : source.file
[tab]command
for example:
target.txt : source.txt
ls
cd
the script works well but it cannot find commands starting with tab. it always execute them. for example, the commands in this input is still executed.
target.txt : source.txt
ls
cd
how can I fix this?
read, which splits on whitespace i.e. including tabs. Perhaps doIFS=' 'at the beginning to let only a space separate words.