2024-02-24 11:38:26 +08:00
|
|
|
<TeXmacs|2.1.2>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
|
|
|
<style|<tuple|article|chinese|old-dots|old-lengths>>
|
|
|
|
|
|
|
|
<\body>
|
2024-02-24 11:38:26 +08:00
|
|
|
<doc-data|<doc-title|Bash\<#811A\>\<#672C\>\<#57FA\>\<#7840\>>|<doc-author|<author-data|<author-name|\<#6C88\>\<#8FBE\>>>>>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<section|\<#8D4B\>\<#503C\>\<#4E0E\>\<#66FF\>\<#6362\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
|
|
|
<\session|shell|default>
|
|
|
|
<\input|Shell] >
|
|
|
|
a=375
|
|
|
|
</input>
|
|
|
|
|
|
|
|
<\input|Shell] >
|
|
|
|
hello=$a
|
|
|
|
</input>
|
|
|
|
|
|
|
|
<\folded-io|Shell] >
|
|
|
|
echo $hello
|
|
|
|
<|folded-io>
|
|
|
|
375
|
|
|
|
</folded-io>
|
|
|
|
|
|
|
|
<\input|Shell] >
|
|
|
|
\;
|
|
|
|
</input>
|
|
|
|
</session>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<section|\<#53D8\>\<#91CF\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
|
|
|
<\description>
|
2024-02-24 11:38:26 +08:00
|
|
|
<item*|\<#5185\>\<#7F6E\>\<#53D8\>\<#91CF\>>\<#6BD4\>\<#5982\><verbatim|$HOME>\<#6216\>\<#8005\><verbatim|$PWD>\<#FF0C\>\<#66F4\>\<#591A\>\<#4F8B\>\<#5B50\>\<#53EF\>\<#4EE5\>\<#53C2\>\<#8003\>
|
2022-05-15 15:35:32 +08:00
|
|
|
<shell|man 7 environ>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<item*|\<#4F4D\>\<#7F6E\>\<#53C2\>\<#6570\>><verbatim|$0>\<#662F\>basename\<#FF0C\><verbatim|$@>\<#662F\>basename\<#4E4B\>\<#540E\>\<#7684\>\<#6240\>\<#6709\>\<#53C2\>\<#6570\>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
|
|
|
<tree|<verbatim|$@>|<verbatim|$1>|<verbatim|$2>|<verbatim|$3>|<verbatim|$4>|<text-dots>>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<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\>
|
2022-05-15 15:35:32 +08:00
|
|
|
</description>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<section|\<#5206\>\<#652F\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
|
|
|
<\shell-code>
|
|
|
|
if [ condition1 ];then
|
|
|
|
|
|
|
|
\ \ \ \ command_series1
|
|
|
|
|
|
|
|
elif [ condition2 ];then
|
|
|
|
|
|
|
|
\ \ \ \ command_series2
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
\ \ \ \ default_command_series3
|
|
|
|
|
|
|
|
fi
|
|
|
|
</shell-code>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<section|\<#5FAA\>\<#73AF\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
|
|
|
<\description>
|
2024-02-24 11:38:26 +08:00
|
|
|
<item*|\<#5FAA\>\<#73AF\>\<#FF1A\>\<#4E0E\>Python\<#8BED\>\<#6CD5\>\<#76F8\>\<#8FD1\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
|
|
|
<\shell-code>
|
|
|
|
for arg in `seq 10`
|
|
|
|
|
|
|
|
do
|
|
|
|
|
|
|
|
\ \ \ \ echo $arg
|
|
|
|
|
|
|
|
done
|
|
|
|
</shell-code>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<item*|\<#5FAA\>\<#73AF\>\<#FF1A\>\<#4E0E\>C\<#8BED\>\<#8A00\>for\<#8BED\>\<#6CD5\>\<#76F8\>\<#8FD1\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
|
|
|
<\shell-code>
|
|
|
|
for ((a=1; a\<less\>=LIMIT; a++))
|
|
|
|
|
|
|
|
do
|
|
|
|
|
|
|
|
\ \ \ \ echo -n "$a "
|
|
|
|
|
|
|
|
done
|
|
|
|
</shell-code>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<item*|\<#5FAA\>\<#73AF\>: \<#4E0E\>C\<#8BED\>\<#8A00\>while\<#8BED\>\<#6CD5\>\<#76F8\>\<#8FD1\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
|
|
|
<\shell-code>
|
|
|
|
a=1
|
|
|
|
|
|
|
|
while ((a\<less\>=LIMIT))
|
|
|
|
|
|
|
|
do
|
|
|
|
|
|
|
|
\ \ \ \ echo -n "$a "
|
|
|
|
|
|
|
|
\ \ \ \ ((a += 1))
|
|
|
|
|
|
|
|
done
|
|
|
|
</shell-code>
|
|
|
|
</description>
|
|
|
|
|
|
|
|
<section|IO>
|
|
|
|
|
|
|
|
<\shell-code>
|
|
|
|
command \<less\> input-file \<gtr\> output-file \ \ \ \ #
|
2024-02-24 11:38:26 +08:00
|
|
|
\<#8BFB\>\<#53D6\>\<#7136\>\<#540E\>\<#8986\>\<#76D6\>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
|
|
|
command \<gtr\>\<gtr\> output-file \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ #
|
2024-02-24 11:38:26 +08:00
|
|
|
\<#8FFD\>\<#52A0\>
|
2022-05-15 15:35:32 +08:00
|
|
|
</shell-code>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<section|\<#51FD\>\<#6570\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
|
|
|
<\shell-code>
|
2024-02-24 11:38:26 +08:00
|
|
|
# \<#5982\>\<#4F55\>\<#5B9A\>\<#4E49\>\<#51FD\>\<#6570\>1
|
2022-05-15 15:35:32 +08:00
|
|
|
|
|
|
|
function fun_name(){
|
|
|
|
|
|
|
|
\ \ \ \ command...
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
# \<#5982\>\<#4F55\>\<#5B9A\>\<#4E49\>\<#51FD\>\<#6570\>2
|
2022-05-15 15:35:32 +08:00
|
|
|
|
|
|
|
fun_name(){ # arg1 arg2 arg3
|
|
|
|
|
|
|
|
\ \ \ \ command...
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
\;
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
# \<#51FD\>\<#6570\>\<#7684\>\<#5E94\>\<#7528\>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
|
|
|
fun_name $arg1 $arg2 $arg3
|
|
|
|
|
|
|
|
\;
|
|
|
|
|
|
|
|
\;
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
# \<#5F15\>\<#7528\>\<#89E3\>\<#9664\>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
|
|
|
fun_name(){ # arg1
|
|
|
|
|
|
|
|
\ \ \ \ eval "$1=hello"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fun_name arg1
|
|
|
|
|
|
|
|
\;
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
# \<#4E0A\>\<#8FF0\>\<#4EE3\>\<#7801\>\<#7247\>\<#6BB5\>\<#7B49\>\<#4EF7\>\<#4E8E\>\
|
2022-05-15 15:35:32 +08:00
|
|
|
|
|
|
|
arg1=hello
|
|
|
|
</shell-code>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<section|\<#8C03\>\<#8BD5\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
|
|
|
<\itemize>
|
2024-02-24 11:38:26 +08:00
|
|
|
<item>\<#7528\>\<#597D\>sh\<#547D\>\<#4EE4\>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
|
|
|
<\description>
|
2024-02-24 11:38:26 +08:00
|
|
|
<item*|sh -n script>\<#68C0\>\<#67E5\>\<#811A\>\<#672C\>\<#8BED\>\<#6CD5\>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<item*|sh -v script>\<#5728\>\<#6267\>\<#884C\>\<#524D\>\<#5C06\>\<#6240\>\<#6709\>\<#547D\>\<#4EE4\>\<#6253\>\<#5370\>\<#51FA\>\<#6765\>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<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\>
|
2022-05-15 15:35:32 +08:00
|
|
|
</description>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<item>\<#5229\>\<#7528\><shell|echo>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<item>\<#5229\>\<#7528\><shell|trap>
|
2022-05-15 15:35:32 +08:00
|
|
|
</itemize>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<section|\<#5E76\>\<#884C\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
\<#5229\>\<#7528\>GNU Parallel<\footnote>
|
2022-05-15 15:35:32 +08:00
|
|
|
<slink|https://www.gnu.org/software/parallel/>
|
|
|
|
</footnote>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<section|\<#4EE3\>\<#7801\>\<#98CE\>\<#683C\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
\<#5229\>\<#7528\>ShellCheck<\footnote>
|
2022-05-15 15:35:32 +08:00
|
|
|
<slink|https://github.com/koalaman/shellcheck>
|
|
|
|
</footnote>
|
|
|
|
</body>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<initial|<\collection>
|
|
|
|
</collection>>
|
|
|
|
|
2022-05-15 15:35:32 +08:00
|
|
|
<\references>
|
|
|
|
<\collection>
|
|
|
|
<associate|auto-1|<tuple|1|?>>
|
|
|
|
<associate|auto-2|<tuple|2|?>>
|
|
|
|
<associate|auto-3|<tuple|3|?>>
|
|
|
|
<associate|auto-4|<tuple|4|?>>
|
|
|
|
<associate|auto-5|<tuple|5|?>>
|
|
|
|
<associate|auto-6|<tuple|6|?>>
|
|
|
|
<associate|auto-7|<tuple|7|?>>
|
|
|
|
<associate|auto-8|<tuple|8|?>>
|
|
|
|
<associate|auto-9|<tuple|9|?>>
|
|
|
|
<associate|footnote-1|<tuple|1|?>>
|
|
|
|
<associate|footnote-2|<tuple|2|?>>
|
|
|
|
<associate|footnr-1|<tuple|1|?>>
|
|
|
|
<associate|footnr-2|<tuple|2|?>>
|
|
|
|
</collection>
|
|
|
|
</references>
|
|
|
|
|
|
|
|
<\auxiliary>
|
|
|
|
<\collection>
|
|
|
|
<\associate|toc>
|
2024-02-24 11:38:26 +08:00
|
|
|
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|1<space|2spc>\<#8D4B\>\<#503C\>\<#4E0E\>\<#66FF\>\<#6362\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
<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>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|2<space|2spc>\<#53D8\>\<#91CF\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
<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>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|3<space|2spc>\<#5206\>\<#652F\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
<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>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|4<space|2spc>\<#5FAA\>\<#73AF\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
<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>
|
|
|
|
|
|
|
|
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|5<space|2spc>IO>
|
|
|
|
<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>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|6<space|2spc>\<#51FD\>\<#6570\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
<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>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|7<space|2spc>\<#8C03\>\<#8BD5\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
<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>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|8<space|2spc>\<#5E76\>\<#884C\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
<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>
|
|
|
|
|
2024-02-24 11:38:26 +08:00
|
|
|
<vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|9<space|2spc>\<#4EE3\>\<#7801\>\<#98CE\>\<#683C\>>
|
2022-05-15 15:35:32 +08:00
|
|
|
<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>
|
|
|
|
</collection>
|
|
|
|
</auxiliary>
|