quoting question

hi guys, i have a question related to quoting but i am not sure how to formulate it...

lets say we want to simulate the following shell actions

cd ~/project-dir
ctags /home/work/folder1/*.sh  /home/work/folder2/*.sh  /home/work/folder3/*.sh 

so i make the following script

buidtags.sh

directory="~/project-dir"
file_locations="/home/work/folder1/*.sh  /home/work/folder2/*.sh  /home/work/folder3/*.sh"

ctags_command=ctags "$file_locations"

(cd "$directory" && $ctags_command )

but it doesn't work...
i think the reason is that it skips file globbing, and considers *.sh to be a file, that (of course) can't be found! How can i make file globbing and double quotes coexist? in other words how can i make this example work?

thanks in advance for your time,
nicolas

PS: in quoting as a reference i use chap7 from "learning the bash shell 3rd edition" but i am relatively new to shell scripting.Is there any other good reference for bash?

The "man" pages are a good reference.

You're right, by the way -- the * doesn't get expanded inside double-quotes. However, it's the ctags_command assignment that would give you problems:

ctags_command=echo separate words must be quoted

Here's another way to do it:

directory="~/project-dir"
file_locations=/home/work/folder[123]/*.sh
ctags_command="ctags $file_locations"

(cd "$directory" && $ctags_command )

Yet another way is with xargs:

directory="~/project-dir"
cd $directory && rm -f tags && find . -name "*.sh" | xargs ctags -a 

The xargs command takes the output from find, and runs the ctags command as many times as needed (not once for each file, but as many times as required if the command line cannot hold all the arguments on one line). The -a command ensures ctags appends to the existing tags file in case xargs does need more than one call.

thank you otheus! that solved the problem