3

I have result of simple command:

   cp -R SourceDir DestDir >out.txt
   result="out.txt"

But if script haven't access to write, how I can get output in variable result?

3 Answers 3

8

You can just do this:

result=$(cp -R SourceDir DestDir)

You can also use this form:

result=`cp -R SourceDir DestDir`

but this is less preferable for several reasons (see http://mywiki.wooledge.org/BashFAQ/082).

Sign up to request clarification or add additional context in comments.

Comments

2
result=$(cp -R SourceDir DestDir)
echo $result

Comments

1

By using backticks (`):

OUTPUT=`cp -R SourceDir DestDir`

Or did I get you wrong?

1 Comment

In general, $(...) should be preferred to backticks; see mywiki.wooledge.org/BashFAQ/082.

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.