Computer Science Canada unix command line arguments |
Author: | Fonzie [ 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. |
Author: | wtd [ Sun Nov 18, 2007 11:19 pm ] |
Post subject: | RE:unix command line arguments |
That is the workaround. |
Author: | Fonzie [ 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? |
Author: | wtd [ 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.
Now, we try to call:
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". |
Author: | Fonzie [ 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 |
Author: | wtd [ Thu Nov 22, 2007 5:44 pm ] |
Post subject: | RE:unix command line arguments |
Effectively, no. Single quoted strings do not undergo variable interpolation. |