1

I have the following script:

rstest

text=$1

cmd="Rscript -e \"a='$1'; print(a)\""
echo $cmd
$cmd

This is the output I get when I run it:

balter@spectre3:~$ bash rstest hello
Rscript -e "a='hello'; print(a)"
Error: unexpected end of input
Execution halted

However, if I run the echoed command directly, it runs fine:

balter@spectre3:~$ Rscript -e "a='hello'; print(a)"

[1] "hello"

I would like to understand why this is. I've tried various combinations of quoting the bash variables and adding eval. But that doesn't seem to be the issue.

EDIT

I tried the answer given below, but get a different result!

balter@spectre3:~$ cat rstest
text=$1

cmd="Rscript -e \"a=$1; print(a)\""
echo $cmd
eval $cmd

balter@spectre3:~$ bash rstest
Rscript -e "a=; print(a)"
Error in cat("pointing to conda env:", env_name, "and lib location", lib,  :
  argument "env_name" is missing, with no default
Calls: startCondaEnv -> cat
Execution halted
2
  • I think you want eval $cmd rather than just $cmd Commented May 15, 2019 at 1:28
  • That did not change the behavior :( Commented May 15, 2019 at 1:59

1 Answer 1

1

Below script worked for me.

text=$1

cmd="Rscript -e \"a='$1'; print(a)\""
echo $cmd
eval $cmd

Removing eval gave the same error you posted.

Rscript -e "a='Hello'; print(a)"
Error: unexpected end of input
Execution halted
Sign up to request clarification or add additional context in comments.

2 Comments

Welcome to Stackoverflow! I added to the original post trying to run what you gave. I get the same error! I'm running this in Ubuntu 18.10. You?
Mint 19.1 and R 3.6.0; i think after you used eval you changed cmd and forget to add the apostrophe around $1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.