?? generate-script.sh
字號:
#!/bin/bash# generate-script.sh# 這個腳本的誕生基于Albert Reiner的一個主意. OUTFILE=generated.sh # 所產生文件的名字. # -----------------------------------------------------------# 'Here document包含了需要產生的腳本的代碼. (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# -----------------------------------------------------------# 將'limit string'引用起來將會阻止上邊#+ here document消息體中的變量擴展. # 這會使得輸出文件中的內容保持here document消息體中的原文. if [ -f "$OUTFILE" ]then chmod 755 $OUTFILE # 讓所產生的文件具有可執行權限. else echo "Problem in creating file: \"$OUTFILE\""fi# 這個方法也可以用來產生#+ C程序代碼, Perl程序代碼, Python程序代碼, makefile, #+ 和其他的一些類似的代碼. # (譯者注: 中間一段沒譯的注釋將會被here document打印出來)exit 0
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -