massive update for Mogan Research 1.2.5

This commit is contained in:
Darcy Shen 2024-02-24 11:38:26 +08:00
parent 64a5d8b40d
commit 73005e7d0a
49 changed files with 3265 additions and 2793 deletions

View file

@ -1,11 +1,11 @@
<TeXmacs|2.1.3>
<TeXmacs|2.1.2>
<style|<tuple|article|chinese|old-dots|old-lengths>>
<\body>
<doc-data|<doc-title|Bash脚本基础>|<doc-author|<author-data|<author-name|沈达>>>>
<doc-data|<doc-title|Bash\<#811A\>\<#672C\>\<#57FA\>\<#7840\>>|<doc-author|<author-data|<author-name|\<#6C88\>\<#8FBE\>>>>>
<section|赋值与替换>
<section|\<#8D4B\>\<#503C\>\<#4E0E\>\<#66FF\>\<#6362\>>
<\session|shell|default>
<\input|Shell] >
@ -27,20 +27,20 @@
</input>
</session>
<section|变量>
<section|\<#53D8\>\<#91CF\>>
<\description>
<item*|内置变量>比如<verbatim|$HOME>或者<verbatim|$PWD>,更多例子可以参考
<item*|\<#5185\>\<#7F6E\>\<#53D8\>\<#91CF\>>\<#6BD4\>\<#5982\><verbatim|$HOME>\<#6216\>\<#8005\><verbatim|$PWD>\<#FF0C\>\<#66F4\>\<#591A\>\<#4F8B\>\<#5B50\>\<#53EF\>\<#4EE5\>\<#53C2\>\<#8003\>
<shell|man 7 environ>
<item*|位置参数><verbatim|$0>是basename<verbatim|$@>是basename之后的所有参数
<item*|\<#4F4D\>\<#7F6E\>\<#53C2\>\<#6570\>><verbatim|$0>\<#662F\>basename\<#FF0C\><verbatim|$@>\<#662F\>basename\<#4E4B\>\<#540E\>\<#7684\>\<#6240\>\<#6709\>\<#53C2\>\<#6570\>
<tree|<verbatim|$@>|<verbatim|$1>|<verbatim|$2>|<verbatim|$3>|<verbatim|$4>|<text-dots>>
<item*|特殊参数><verbatim|$?>是命令、函数或者脚本本身的返回状态一般用0表示一切正常
<item*|\<#7279\>\<#6B8A\>\<#53C2\>\<#6570\>><verbatim|$?>\<#662F\>\<#547D\>\<#4EE4\>\<#3001\>\<#51FD\>\<#6570\>\<#6216\>\<#8005\>\<#811A\>\<#672C\>\<#672C\>\<#8EAB\>\<#7684\>\<#8FD4\>\<#56DE\>\<#72B6\>\<#6001\>\<#FF0C\>\<#4E00\>\<#822C\>\<#7528\>0\<#8868\>\<#793A\>\<#4E00\>\<#5207\>\<#6B63\>\<#5E38\>
</description>
<section|分支>
<section|\<#5206\>\<#652F\>>
<\shell-code>
if [ condition1 ];then
@ -58,10 +58,10 @@
fi
</shell-code>
<section|循环>
<section|\<#5FAA\>\<#73AF\>>
<\description>
<item*|循环与Python语法相近>
<item*|\<#5FAA\>\<#73AF\>\<#FF1A\>\<#4E0E\>Python\<#8BED\>\<#6CD5\>\<#76F8\>\<#8FD1\>>
<\shell-code>
for arg in `seq 10`
@ -73,7 +73,7 @@
done
</shell-code>
<item*|循环与C语言for语法相近>
<item*|\<#5FAA\>\<#73AF\>\<#FF1A\>\<#4E0E\>C\<#8BED\>\<#8A00\>for\<#8BED\>\<#6CD5\>\<#76F8\>\<#8FD1\>>
<\shell-code>
for ((a=1; a\<less\>=LIMIT; a++))
@ -85,7 +85,7 @@
done
</shell-code>
<item*|循环: 与C语言while语法相近>
<item*|\<#5FAA\>\<#73AF\>: \<#4E0E\>C\<#8BED\>\<#8A00\>while\<#8BED\>\<#6CD5\>\<#76F8\>\<#8FD1\>>
<\shell-code>
a=1
@ -106,16 +106,16 @@
<\shell-code>
command \<less\> input-file \<gtr\> output-file \ \ \ \ #
读取然后覆盖
\<#8BFB\>\<#53D6\>\<#7136\>\<#540E\>\<#8986\>\<#76D6\>
command \<gtr\>\<gtr\> output-file \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ #
追加
\<#8FFD\>\<#52A0\>
</shell-code>
<section|函数>
<section|\<#51FD\>\<#6570\>>
<\shell-code>
# 如何定义函数1
# \<#5982\>\<#4F55\>\<#5B9A\>\<#4E49\>\<#51FD\>\<#6570\>1
function fun_name(){
@ -123,7 +123,7 @@
}
# 如何定义函数2
# \<#5982\>\<#4F55\>\<#5B9A\>\<#4E49\>\<#51FD\>\<#6570\>2
fun_name(){ # arg1 arg2 arg3
@ -133,7 +133,7 @@
\;
# 函数的应用
# \<#51FD\>\<#6570\>\<#7684\>\<#5E94\>\<#7528\>
fun_name $arg1 $arg2 $arg3
@ -141,7 +141,7 @@
\;
# 引用解除
# \<#5F15\>\<#7528\>\<#89E3\>\<#9664\>
fun_name(){ # arg1
@ -153,42 +153,45 @@
\;
# 上述代码片段等价于\
# \<#4E0A\>\<#8FF0\>\<#4EE3\>\<#7801\>\<#7247\>\<#6BB5\>\<#7B49\>\<#4EF7\>\<#4E8E\>\
arg1=hello
</shell-code>
<section|调试>
<section|\<#8C03\>\<#8BD5\>>
<\itemize>
<item>用好sh命令
<item>\<#7528\>\<#597D\>sh\<#547D\>\<#4EE4\>
<\description>
<item*|sh -n script>检查脚本语法
<item*|sh -n script>\<#68C0\>\<#67E5\>\<#811A\>\<#672C\>\<#8BED\>\<#6CD5\>
<item*|sh -v script>在执行前将所有命令打印出来
<item*|sh -v script>\<#5728\>\<#6267\>\<#884C\>\<#524D\>\<#5C06\>\<#6240\>\<#6709\>\<#547D\>\<#4EE4\>\<#6253\>\<#5370\>\<#51FA\>\<#6765\>
<item*|sh -x script>在执行前将所有命令到打印到错误输出,并在命令前面加上<shell|+>前缀
<item*|sh -x script>\<#5728\>\<#6267\>\<#884C\>\<#524D\>\<#5C06\>\<#6240\>\<#6709\>\<#547D\>\<#4EE4\>\<#5230\>\<#6253\>\<#5370\>\<#5230\>\<#9519\>\<#8BEF\>\<#8F93\>\<#51FA\>\<#FF0C\>\<#5E76\>\<#5728\>\<#547D\>\<#4EE4\>\<#524D\>\<#9762\>\<#52A0\>\<#4E0A\><shell|+>\<#524D\>\<#7F00\>
</description>
<item>利用<shell|echo>
<item>\<#5229\>\<#7528\><shell|echo>
<item>利用<shell|trap>
<item>\<#5229\>\<#7528\><shell|trap>
</itemize>
<section|并行>
<section|\<#5E76\>\<#884C\>>
利用GNU Parallel<\footnote>
\<#5229\>\<#7528\>GNU Parallel<\footnote>
<slink|https://www.gnu.org/software/parallel/>
</footnote>
<section|代码风格>
<section|\<#4EE3\>\<#7801\>\<#98CE\>\<#683C\>>
利用ShellCheck<\footnote>
\<#5229\>\<#7528\>ShellCheck<\footnote>
<slink|https://github.com/koalaman/shellcheck>
</footnote>
</body>
<initial|<\collection>
</collection>>
<\references>
<\collection>
<associate|auto-1|<tuple|1|?>>
@ -210,19 +213,19 @@
<\auxiliary>
<\collection>
<\associate|toc>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|1<space|2spc>赋值与替换>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|1<space|2spc>\<#8D4B\>\<#503C\>\<#4E0E\>\<#66FF\>\<#6362\>>
<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
<no-break><pageref|auto-1><vspace|0.5fn>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|2<space|2spc>变量>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|2<space|2spc>\<#53D8\>\<#91CF\>>
<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
<no-break><pageref|auto-2><vspace|0.5fn>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|3<space|2spc>分支>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|3<space|2spc>\<#5206\>\<#652F\>>
<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
<no-break><pageref|auto-3><vspace|0.5fn>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|4<space|2spc>循环>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|4<space|2spc>\<#5FAA\>\<#73AF\>>
<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
<no-break><pageref|auto-4><vspace|0.5fn>
@ -230,19 +233,19 @@
<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
<no-break><pageref|auto-5><vspace|0.5fn>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|6<space|2spc>函数>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|6<space|2spc>\<#51FD\>\<#6570\>>
<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
<no-break><pageref|auto-6><vspace|0.5fn>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|7<space|2spc>调试>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|7<space|2spc>\<#8C03\>\<#8BD5\>>
<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
<no-break><pageref|auto-7><vspace|0.5fn>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|8<space|2spc>并行>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|8<space|2spc>\<#5E76\>\<#884C\>>
<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
<no-break><pageref|auto-8><vspace|0.5fn>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|9<space|2spc>代码风格>
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|9<space|2spc>\<#4EE3\>\<#7801\>\<#98CE\>\<#683C\>>
<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
<no-break><pageref|auto-9><vspace|0.5fn>
</associate>