I have a bash script like
./script -a filename
And I have the content of a file in a variable $CONTENT
How can I pass the variable into the command. I mean I could write the content of the variable down to disk first, but that seems to be too much overhead.
Is there a better solution?
Something like
./scrip -a << $CONTENT
You need one more <
:
./script -a <<<"$CONTENT"
<<<
is called a herestring, and takes the following string and passes it as the standard input.
Kevin's suggestion to use a here string will work, as long as you quote the variable as suggested in the comments to that answer. A more portable solution is to use a here doc:
./script -a << EOF
$CONTENT
EOF
In this case, quotes are not necessary and indeed undesirable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.