heredoc in shell
heredoc 参考下面几个链接 http://en.wikipedia.org/wiki/Here_document http://tldp.org/LDP/abs/html/here-docs.html $ cat « EOF > Working dir $PWD > EOF Working dir /home/user 不解释变量 $ cat « “EOF” > Working dir $PWD > EOF Working dir $PWD 创建脚本的脚本 #!/bin/bash OUTFILE=generated.sh # Name of the file to generate. ( cat «‘EOF’ #!/bin/bash echo “This is a generated shell script.” # Note that since we are inside a subshell, #+ we can’t access variables in the “outside” script. echo “Generated file will be named: $OUTFILE” a=7 b=3 let “c = $a * $b” echo “c = $c” exit 0 EOF ) > $OUTFILE if [ -f “$OUTFILE” ] then chmod 755 $OUTFILE else echo “Problem in creating file: "$OUTFILE"” fi exit 0 ...