Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 unix command line arguments
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Fonzie




PostPosted: Sun Nov 18, 2007 3:59 pm   Post subject: unix command line arguments

If I have a unix script and I send it the following command line argument:

a3 c makemoneyfa$t

I am returned with the message:

t: Undefined variable

I know this is because the '$' symbol is special, but I was wondering if there was some kind of work around for this. I know I could give the command line:

a3 c makemoneyfa\$t

but I was wondering if there's something I could put inside my program itself, rather than the command line, that could defend against special characters in command line arguments.
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Sun Nov 18, 2007 11:19 pm   Post subject: RE:unix command line arguments

That is the workaround.
Fonzie




PostPosted: Mon Nov 19, 2007 11:10 am   Post subject: Re: unix command line arguments

but that's something the user would be doing when trying to use the program. Is there nothing I can do so that the user can have special characters in their filename and my script be able to handle it?
wtd




PostPosted: Mon Nov 19, 2007 11:25 am   Post subject: RE:unix command line arguments

I think you may be confused by the order of evaluation.

Let's say we really do have a variable t.

code:
t=foo


Now, we try to call:

code:
bar baz$t


The "bar" program does not see "baz$t" as its first argument and then magically turn that into "bazfoo".

Rather, the shell turns "baz$t" into "bazfoo" and then sends that to "bar".
Fonzie




PostPosted: Thu Nov 22, 2007 5:22 pm   Post subject: Re: unix command line arguments

thankyou, I think I understand. I'm curious though, is there a difference between these two lines?

a3 c 'makemoneyfa$t'
a3 c makemoneyfa\$t
wtd




PostPosted: Thu Nov 22, 2007 5:44 pm   Post subject: RE:unix command line arguments

Effectively, no.

Single quoted strings do not undergo variable interpolation.
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: