本文为Bash Scripting Full Course 3 Hours学习笔记
(此基础上补充)

(base) lighthouse@VM-8-2-ubuntu:~$ cat /etc/shells  # 所有可用shell
# /etc/shells: valid login shells
/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/bin/dash
/usr/bin/dash
/usr/bin/tmux
/usr/bin/screen

(base) lighthouse@VM-8-2-ubuntu:~$ which bash
/usr/bin/bash

多行注释和多行提示

多行注释 invisible

多行提示 visible

bash调用javascript bash scripting_bash


bash调用javascript bash scripting_读取文件_02


条件语句

bash调用javascript bash scripting_读取文件_03


注意

① 前后空格

②$

③ [-eq -gt -lt] 等同于((= > <))

le小于等于<=

④[] && || [] 等同于 (()) && || (()) 等同于 括号(([ -a -o 反括号

习惯语句:

<<BLOCK
if [ $count -eq 10 ]
then
        echo 'T'
else
        echo 'F'
fi
BLOCK

if (( $count > 7 )) && (( $count < 12))
then
        echo 'T'
elif (( $count > 29)) || (( $count < 3))
then
        echo 'T`'
else
        echo 'F'
fi

循环

while until

for

bash调用javascript bash scripting_开发语言_04


for

if break/continue

bash调用javascript bash scripting_linux_05


(( = ))

attempted assignment to non-variable

? ((==))


bash脚本输入

bash调用javascript bash scripting_bash_06

bash调用javascript bash scripting_开发语言_07


bash调用javascript bash scripting_bash调用javascript_08


NB: $ 在变量操作括号外 如 n=$(n-1) echo ${args[1]}


按行读取文件

bash调用javascript bash scripting_读取文件_09


Bash读取文件read 内部命令被用来从标准输入读取单行数据。这个命令可以用来读取键盘输入,当使用重定向的时候,可以读取文件中的一行数据。


bash脚本输出

bash调用javascript bash scripting_linux_10



export

send output from one script to another script

bash调用javascript bash scripting_开发语言_11


bash调用javascript bash scripting_读取文件_12

bash调用javascript bash scripting_linux_13


字符串操作

区别于前 数值操作

bash调用javascript bash scripting_读取文件_14


bash调用javascript bash scripting_linux_15


bash调用javascript bash scripting_bash_16


数值操作

bash调用javascript bash scripting_linux_17


bash调用javascript bash scripting_bash调用javascript_18


声明变量

declare

bash调用javascript bash scripting_bash_19


bash调用javascript bash scripting_bash_20


对变量进行限制


Arrays

联系前面bash脚本输入array

bash调用javascript bash scripting_bash调用javascript_21


bash调用javascript bash scripting_bash调用javascript_22


函数

bash调用javascript bash scripting_bash_23


函数构造形式类似R

bash中变量输入通过输入位次来决定 $1 $…


发送邮件

bash调用javascript bash scripting_linux_24


我在想是否在每次nohup & 结束后通过邮件把log发给我自己

值得探索


web文件下载

curl

bash调用javascript bash scripting_读取文件_25


curl 和Wget功能比较

professional menu

bash调用javascript bash scripting_读取文件_26


交互选择 select opttion + case loop

bash调用javascript bash scripting_开发语言_27


交互“按任意键退出” read -t -3 -n 1 # -t每三秒 -n 参数设置 read 命令计数输入的字符


inotify

bash调用javascript bash scripting_bash调用javascript_28


监控目录文件夹行为


grep、awk、sed

Linux笔记丨三剑客是谁?grep、sed、awk

bash调用javascript bash scripting_开发语言_29


(注意read 可读取整行输入 且不需$ 如$1 $2等)awk像一门单独的编程语言

bash调用javascript bash scripting_linux_30


sed

bash调用javascript bash scripting_读取文件_31


debug

bash调用javascript bash scripting_读取文件_32


bash调用javascript bash scripting_linux_33