Re: NSString and special characters
Re: NSString and special characters
- Subject: Re: NSString and special characters
- From: Jason Coco <email@hidden>
- Date: Fri, 22 Aug 2008 08:51:08 -0400
On Aug 22, 2008, at 05:26 , Vladimir Sokolov wrote:
2008/8/22, Bill Bumgarner <email@hidden>:
On Aug 22, 2008, at 1:00 AM, Vladimir Sokolov wrote:
Hello All,
I am working on a command line tool. I use
NSArray *params = [[NSProcessInfo processInfo] arguments]
to get a list of command line parameters.
Then I use
NSString *param1 = [params objectAtIndex:1];
to get it.
But when I pass for example >...myapplication test$test
param1 got "testest" instead of ""test$test"
It means as I understand that $ is interpreted as special character.
So my question is how to pass a parameter with $ inside?
And are there any other special characters which are interpreted as
special
one?
To be clear, this has nothing to do with NSString and everything to
do with
how the shell parses command lines.
As Michael D alluded to, the shell is seeing $test and "expanding"
the $t
to be the value of -- typically -- the environment variable 't',
which
doesn't have a value and, thus, you end up with 'testest'.
That is, all argument processing has been completed long before your
command line tool is even launched.
Now, the syntax and rules for substitution change depending on the
shell
used and how your command line tool is launched. As well, APIs for
launching processes such as NSTask, popen(), system(), and the
various
fork()/exec*() combinations may or may not behave similarly.
So -- the real questions:
What is launching your command line tool?
Do you really need an argument with a $ character in it?
Most command line tools avoid such characters for the reasons
stated above.
Have you read this book? http://tinyurl.com/6kxxgc
b.bum
Thanks for your messages.
Now I see my problem ( Learn Unix! :))
The $ character is part of the user password, that is why I need to
use it.
Now for the test I am launching my tool in bash.
If you're using bash you can surround the argument in single quotes
(e.g., 'test$test') and it won't do any expansion.
However, it's a really bad idea to pass a password on the command line
in Unix in general because any application can read your
process's argument list without any special privileges.
Jason
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden