You need to use command substitution:
#!/usr/bin/env bash test=$(grep 'foo' "$1") echo "$test"
Team substitution allows you to display a command to replace the command itself. Command substitution occurs when a command is enclosed in the following command:
$(command)
or so using backlinks:
`command`
Bash performs the extension by executing the COMMAND command and replacing command substitution with the standard command output, removing any trailing lines. Inline newlines are not deleted, but they can be deleted during word splitting.
The $() version is usually preferable because it allows nesting:
$(command $(command))
For more information, read the command substitution section in man bash .
Chris seymour
source share