Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > screwy c-shell script problem

screwy c-shell script problem
Thread Tools
Grizzled Veteran
Join Date: Sep 2000
Location: Springfield, MA
Status: Offline
Reply With Quote
Jun 21, 2001, 03:13 PM
 
I have just wasted way too much time at work trying to solve this question. I came across the problem while working on parsing script arguments. In a highly simplified form here is an example of the problem:

#!/bin/csh -f

set arg="-a"
if ( $arg =~ -*a* ) then # this works ok
echo "### -a =~ -a"
else
echo "### -a !~ -a"
endif

set arg="-f"
if ( $arg =~ -*f* ) then # looks the same, but doesn't work
echo "### -f =~ -f"
else
echo "### -f !~ -f"
endif
-f isn't the only value for arg that will cause an error, does anyone have any idea why the letter I use is causing me problems?

The "-" seems to be part of the problem, but I tried quoting the string and escaping the "-" and those didn't help.

Ideas anyone?

TIA

[ 06-21-2001: Message edited by: Mactoid ]
We hope your rules and wisdom choke you / Now we are one in everlasting peace
-- Radiohead, Exit Music (for a film)
     
Senior User
Join Date: Sep 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jun 22, 2001, 07:44 AM
 
possibly because the shell is interpreting the -f (which is a valid shell option) vs. the -a which isn't and thus passed on.
     
Mactoid  (op)
Grizzled Veteran
Join Date: Sep 2000
Location: Springfield, MA
Status: Offline
Reply With Quote
Jun 22, 2001, 08:46 AM
 
I think i'm understanding, the -f is actually being interpreted as an operator.
<3 minutes later>
Ah-ha. That was the problem. I fixed it by quoting $arg. Thanks for the input howardm4
We hope your rules and wisdom choke you / Now we are one in everlasting peace
-- Radiohead, Exit Music (for a film)
     
   
Thread Tools
Forum Links
Forum 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
Top
Privacy Policy
All times are GMT -5. The time now is 12:23 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2