generate-script.sh

来自「Shall高级编程」· Shell 代码 · 共 51 行

SH
51
字号
#!/bin/bash# generate-script.sh# Based on an idea by Albert Reiner.OUTFILE=generated.sh         # Name of the file to generate.# -----------------------------------------------------------# 'Here document containing the body of the generated script.(cat <<'EOF'#!/bin/bashecho "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"#  Above line will not work as normally expected#+ because parameter expansion has been disabled.#  Instead, the result is literal output.a=7b=3let "c = $a * $b"echo "c = $c"exit 0EOF) > $OUTFILE# -----------------------------------------------------------#  Quoting the 'limit string' prevents variable expansion#+ within the body of the above 'here document.'#  This permits outputting literal strings in the output file.if [ -f "$OUTFILE" ]then  chmod 755 $OUTFILE  # Make the generated file executable.else  echo "Problem in creating file: \"$OUTFILE\""fi#  This method can also be used for generating#+ C programs, Perl programs, Python programs, Makefiles,#+ and the like.exit 0

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?