It is currently Wed Jan 18, 2017 4:08 am

$ 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$

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.


 PostPosted: Wed Apr 29, 2009 1:11 am   

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

echo test$1

[email protected]:~> sh test

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

Best regards
Fredrik Eriksson

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

Joined: Thu Oct 11, 2007 7:12 am
Posts: 265
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;


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 :)

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 4 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