0

I have a bash script that arrives like:

SCRIPT=$(curl .... | parsing...)

echo $SCRIPT > myfile

But when I try to echo it in a file, some parts get evaluated. (Variables are substituted if any are defined, the * character is replaced by all files in the working directory, etc...)

Can I prevent bash from evaluating any content of a variable, while still echoing?

2
  • 1
    Quote your variable: echo "$SCRIPT" > myfile Commented Sep 16, 2017 at 11:35
  • 3
    Or else don't even create a variable and use: curl .... | parsing... > myfile Commented Sep 16, 2017 at 11:35

1 Answer 1

1

Yes, use double quotes for that. I'll demonstrate:

$ x='*'

$ echo $x
..list of files..

$ echo '$x'
$x

$ echo "$x"
*
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, seems to work. There were more quotes involved in the curl code before I simplyfied it and that must have been why double quotes echo didn't work for me then.

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.