I have a short bash script to get source code’s dependency files.
#!/bin/sh
rule=$(cpp -P -w -undef -nostdinc -C -M file.cc)
rule=${rule##*:}
#echo $rule
echo ${rule//\\}
Unfortunately, it outputs ./findDep.sh: 5: ./findDep.sh: Bad substitution.
But if I uncomment echo $rule, the script will execute without any problem:
lib.h macro.inc fundamental.h lib/fs.h lib/net.h \ lib/net/fetch.h
lib.h macro.inc fundamental.h lib/fs.h lib/net.h lib/net/fetch.h
Any one know why?
Thanks in advance.
I can’t reproduce your problem here with Bash 4.2.29.
However, did you know that
readwill join lines with\newline continuations by default?Or, in a more
sh-compatible way (I think),