The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
BASH quoting behavior na5m Shell Programming and Scripting 5 12-30-2008 02:31 PM
Quoting problem with `date` cleansing_flame Shell Programming and Scripting 3 02-22-2008 03:26 PM
*.pm globs without quoting, *.pl doesn't. tphyahoo Shell Programming and Scripting 2 06-02-2006 11:37 AM
Quoting of special characters vibhor_agarwali UNIX for Dummies Questions & Answers 1 01-30-2005 04:58 AM
Wildcards and quoting Bab00shka UNIX for Dummies Questions & Answers 2 09-16-2002 10:16 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-05-2009
aegis aegis is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 4
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
Code:
cd ~/project-dir
ctags /home/work/folder1/*.sh  /home/work/folder2/*.sh  /home/work/folder3/*.sh
so i make the following script

buidtags.sh
Code:
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?
  #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,884
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.
  #3 (permalink)  
Old 01-08-2009
aegis aegis is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 4
thank you otheus! that solved the problem
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:16 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0