If you needed to use echo (e.g. if there were other strings to add ... )
echo "I found [" $(find "$d" -name "$b" -type f -print) "]"
(Note that the quotes are fixed as per @suicidaleggroll.)
Also, note that your example
marg './foo/*' bar/
calls marg with two arguments because there is white space between '
Since your script only has one argument, the second one is ignored (after it is expanded). That's why you don't see bar
anywhere in your example output.
In line with @habitual's suggestion,
I have a file called bash_trace
in my ~/bin
directory which contains:
shopt -s -o xtrace # debug
shopt -s -o verbose # debug
If I have a script I will use more than once or that needs work, I often include the line
##source "~/bin/bash_trace" ## debug
in it somewhere near the top. Then, whenever staring at the code isn't enough, I just uncomment that line and run it again to get a full trace. This lets me set and unset both options just by uncommenting or commenting out one line.
statement or just plain .
tells bash to read that file as if it was part of the script - just like an include statement in other languages.
sets shell options. (There are a lot of them.) -s
stands for set or turn on and -o
says which option to affect.
is the same as the -v
command line option which prints shell command lines as they are read.
is the same as the -x
command line option which prints the command line after it has been expanded.
This lets you see the command the way you wrote it and then shows you what "marvelous" things bash did to expand it before actually trying to execute it.