LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-21-2010, 07:35 AM   #1
atbrew
LQ Newbie
 
Registered: Jul 2010
Posts: 4

Rep: Reputation: 0
escaping a single quote from a bash script


Hi,
There is probably a very simple fix, but its wrecking my buzz

I call the following on the command line

R CMD BATCH '--args Y_filename="one.txt" out="two.txt"' brew.R

I want to call this from a bash script but replace one.txt with $1, and two.txt with $2 (ie the first two arguments from the command line)

I have tried in vane


"R CMD BATCH '--args Y_filename=\"$1\" out=\"$2\"' brew.R"

any ideas?

Thanks in advance,
Brew
 
Old 07-21-2010, 07:40 AM   #2
miedward
Member
 
Registered: Feb 2007
Distribution: RHEL 4, SOLARIS 10
Posts: 91

Rep: Reputation: 15
Quote:
Originally Posted by atbrew View Post
Hi,

"R CMD BATCH '--args Y_filename=\"$1\" out=\"$2\"' brew.R"
Try
`R CMD BATCH \'--args Y_filename=\"$1\" out=\"$2\"\' brew.R`
 
Old 07-21-2010, 07:57 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Backtics ( ` ) are normally used for command substition, but "$(......)" is now preferred.

Regardless, I'm not sure how this will address the question.

atbrew;
What is the command being run? eg is it "R" or "R CMD BATCH"? If the latter, then what stops the shell from just trying to run "R"?

second, why the single quotes in your first example?
 
Old 07-21-2010, 08:05 AM   #4
atbrew
LQ Newbie
 
Registered: Jul 2010
Posts: 4

Original Poster
Rep: Reputation: 0
miedward sorry that aint working...

pixellany so I am calling a stats program call R

the arguments CMD and BATCH are arguments for R, the bit in single quotes are the arguments R then passes on to the R script brew.R

so as I said from the command line I call

R CMD BATCH '--args Y_filename="one.txt" out="two.txt"' brew.R

and I just want/need to be able to replicate that from within a bash script.
 
Old 07-21-2010, 08:11 AM   #5
atbrew
LQ Newbie
 
Registered: Jul 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Unhappy Horrible hack

So the horrible hack we have that works is

Code:
#!/bin/bash
CMD="/usr/bin/R CMD BATCH '--args input=\"${1}\" output=\"${2}\"' brew.R"
echo $CMD > temp.sh
exec sh temp.sh
 
Old 07-21-2010, 08:14 AM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Again, why the single quotes? (And why is --args inside the quotes?)

Will any of these work?

Code:
R CMD BATCH --args Y_filename=one.txt out=two.txt brew.R

R CMD BATCH --args "Y_filename=one.txt out=two.txt" brew.R

R CMD BATCH --args "Y_filename=$1 out=$2" brew.R
 
Old 07-21-2010, 08:19 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
So I am a little bit confused (this is easily done some times), but why not just alternate your quotes to get what you want?
Code:
/usr/bin/R CMD BATCH '--args input='"${1}"' output='"${2}" brew.R
This type works when using say awk and trying to include script variables. You may need to play with this a bit as I do not have the R program
so cannot test.
 
Old 07-21-2010, 08:28 AM   #8
atbrew
LQ Newbie
 
Registered: Jul 2010
Posts: 4

Original Poster
Rep: Reputation: 0
grail that worked, thanks a million,
 
Old 07-21-2010, 09:21 AM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
No probs ... please remember to mark as SOLVED once you have a solution.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Escaping the parentheses characters in a bash script which calls find with -prune paul.richter Linux - Newbie 9 07-07-2010 09:59 PM
[SOLVED] Bash Script combination of sed with pwd command escaping slashes HaukeG Programming 2 10-06-2009 04:04 AM
how to use single quote in bash shell like: echo ''\''' linuxtyh Linux - General 6 12-11-2008 11:56 PM
escaping ':' character in bash script paulyche Linux - General 2 11-07-2006 07:18 AM
Bash script - escaping whitespaces colabus Linux - Newbie 15 04-29-2006 11:58 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration