The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 01-05-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,893
Quote:
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:

Code:
ctags_command=echo separate words must be quoted

Here's another way to do it:

Code:
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:

Code:
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.