如何读取 cat << EOF > 中的文件
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
按需打印
愿望输出
$cat test.sh
#!/bin/bash
some commands
ad3
c43
34e
se3
we3
some commands
我想你正在寻找类似的东西?
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
您可以使用复合命令:
{ cat << EOF ; cat file ; cat << EOF2; } > test.sh
> start
> EOF
> more
> EOF2
这给出:
start
ad3
c43
34e
se3
we3
more
我想在 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
愿望输出
$cat test.sh
#!/bin/bash
some commands
ad3
c43
34e
se3
we3
some commands
我想你正在寻找类似的东西?
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
您可以使用复合命令:
{ cat << EOF ; cat file ; cat << EOF2; } > test.sh
> start
> EOF
> more
> EOF2
这给出:
start
ad3
c43
34e
se3
we3
more