Register
It is currently Thu Apr 24, 2014 4:48 pm

$ in command line args


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Tue Apr 28, 2009 3:35 pm   

Joined: Tue Apr 28, 2009 3:26 pm
Posts: 1
I'm trying to generate a command line dynamically and execute it, and the arguments have the $ character in them. For instance:
jar cvf abc.jar some/path/Module$1.java

I've tried leaving the arg as it is, escaping the $ with \, enclosing the arg in single or double quotes, with or without the escape character, and various other things, but nothing works (I get File Not Found, and the file is there). Of course, if I simply typed the above command in at the command prompt, it would work perfectly.

Suggestions would be appreciated.

--Mike


Top
 Profile  
 PostPosted: Wed Apr 29, 2009 1:11 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
That should work tbh.

Code:
#!/bin/sh
echo test$1


frer@trx7:~> sh test.sh test
testtest

the shell should evaluate the variable as normal.
You can try encasing it with ${1} instead :)

Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Wed Apr 29, 2009 9:28 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 224
Location: London - UK
If I understand correctly you want to be able to have an actual $ in the filename. Sadly you will need a \ for each shell/subshell that it's processed through. You may need multiple \ to get through all shells, eg;

./command my\\\$arg

In that case the first \ escapes the second \ and the third \ escapes the $ so the following survives;

my\$arg

The next shell would then have the $ correctly escaped. Quotes will only help to escape the $ in the current shell.

It's difficult to tell if this is actually what you're after without any code example or more info but I hope it's clear enough to help a little :)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP