bash run script from here doc [duplicate]
问题 This question already has answers here : Using variables inside a bash heredoc (3 answers) Closed 9 months ago . In the code below, variable X is output normally. # cat a.sh X=world echo 'hello' $X # cat a.sh | bash hello world But, using here doc, variable X is not displayed. # cat <<EOF | bash > X=world > echo 'hello' $X > EOF hello # bash -s <<EOF > X=world > echo 'hello' $X > EOF hello What made this difference? 回答1: You can see what happens when you remove the |bash X=oldvalue cat <<EOF