
-----------------------------------
Fonzie
Sun Nov 18, 2007 3:59 pm

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.

-----------------------------------
wtd
Sun Nov 18, 2007 11:19 pm

RE:unix command line arguments
-----------------------------------
That is the workaround.

-----------------------------------
Fonzie
Mon Nov 19, 2007 11:10 am

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
Mon Nov 19, 2007 11:25 am

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.

t=foo

Now, we try to call:

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
Thu Nov 22, 2007 5:22 pm

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
Thu Nov 22, 2007 5:44 pm

RE:unix command line arguments
-----------------------------------
Effectively, no.

Single quoted strings do not undergo variable interpolation.
