[英]How can I read a file in cat << EOF >
我想在 cat << 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
打印
欲望 output
$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
我认为您正在寻找类似的东西?
cat > test.sh <<EOF
#!/bin/bash
some commands
ad3
c43
34e
se3
we3
some commands
EOF
您可以使用反引号,或分块写入文件:
#!/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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.