我想在cat中打印一个文件<lt;EOF>。例如
$cat file
ad3
c43
34e
se3
we3
我的脚本是:
$cat run.sh
cat << EOF > test.sh
#!/bin/bash
some commands
cat file #I would like to print the content of the file here
some commands
EOF
我无法使用./run.sh
按需打印
期望输出
$cat test.sh
#!/bin/bash
some commands
ad3
c43
34e
se3
we3
some commands
您可以使用一个复合命令:
{ cat << EOF ; cat file ; cat << EOF2; } > test.sh
> start
> EOF
> more
> EOF2
这就给出了:
start
ad3
c43
34e
se3
we3
more
您可以使用backticks,或者将文件分块写入:
#!/bin/bash
cat <<OMG >zfile
ad3
c43
34e
se3
we3
OMG
# Method1 : backticks
cat << EOF > test.sh
#!/bin/bash
some commands1
`cat zfile`
some commands2
EOF
# Method2: append
cat << EOF1 > test2.sh
#!/bin/bash
some commands1
EOF1
cat zfile >> test2.sh
cat << EOF2 >> test2.sh
some commands2
EOF2
我想你正在搜索类似的东西?
cat > test.sh <<EOF
#!/bin/bash
some commands
ad3
c43
34e
se3
we3
some commands
EOF