How to Get Printed Command Information in Shell Script

I would like to issue a command in a shell script.

This command will have a return code, 0 or non-0, if success or not.

If successful, he will print something.

Now I need to print the material in a shell script. How can i do this?

I know that I can redirect the file and then read the file. Is there a way to redirect it to a variable directly?

Thanks so much for your info.

+3
source share
2 answers

You can use the operator $(...)to capture the output of a command as a string. You may also have seen the old backtick syntax `...`that does the same.

output=$(command)
output=`command`

echo "$output"

Team Replacement

. :

$(command)

`command`

Bash , , . , . $(cat file) , $(< file).

, , $, ` \. backquote, , . $(command) ; .

. , backquotes .

, .

+4
var=`command`

.

+2

Source: https://habr.com/ru/post/1763144/


All Articles