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
Globbing slash Wildcarding Question scotbuff Shell Programming and Scripting 4 02-02-2007 12:10 AM
Sun: High kernel usage & very high load averages lorrainenineill UNIX for Advanced & Expert Users 4 02-06-2006 12:32 PM
Preventing wildcard expansion in "read" gaijin 06 UNIX for Dummies Questions & Answers 8 11-01-2005 09:31 PM
awk / bash globbing question franzke Shell Programming and Scripting 3 07-14-2005 11:55 PM
Find wildcard .shtml files in wildcard directories and removing them- How's it done? Neko UNIX for Dummies Questions & Answers 1 06-27-2001 09:06 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-24-2008
zoo591 zoo591 is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 20
globbing, $# is too high after wildcard expansion in bash script

How can I pass in an argument such as "*.k" to a bash script
without having to double-quote *.k and not having *.k
`glob` to match all files in the pattern?

I tried using noglob in my script but this didn't work the way I thought
it would.. expansion is still occuring, $# is higher than I expect.

Code:
set +o noglob
$# represents *.k pattern after expansion (I dont want that) plus
the other positional parameters that I'm passing in.

Code:
# Test argument count
USAGE="USAGE: $0 <vertical> <src module> <files(s)> "
#
echo $# $0 $1 $2 $3
if [ $# -ne 3 ]
then
   if [ $# -ne 1 -a $1 != "bdat" -a $1 != "cdat" -a $1 != "fdat" -a $1 != "blay" ]
   then
      echo $# $0 $1 $2 $3
      echo $USAGE ; exit 1
   fi
fi

TIA
Zoo591
  #2 (permalink)  
Old 07-25-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
We had this discussion in a similar thread recently I think. There's no way you can avoid the globbing occurring within your script because it is performed by the calling shell. If you can live with turning off globbing in your normal shell (which I suspect is unlikely) then you can turn it off there before running your script.

A suggestion here was to use an alias to turn off globbing, however there is no easy way to turn it back on automagically:

UNIX Scripting - Turn off file expansion for command line arguments
  #3 (permalink)  
Old 07-25-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
In shell programming / aliasing / set -f this was fixed by combining an alias and a shell function.
  #4 (permalink)  
Old 07-25-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Nice solution; only seems to work in bash as you surmised in the referenced thread, but that'll be good enough for the OP!
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:44 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