我们经常会在cmd上写一些命令,而这些命令其实也可以在bash中执行,bash增加了更多的语法,让我们可以写出比较简单的处理流程
bash中的分支结构
条件
if express; then
fi
express:
1、[]
while
while xxx; do
express
done
express可以是case语句,可以是其它语句
方法
https://stackoverflow.com/questions/6212219/passing-parameters-to-a-bash-function
There are two typical ways of declaring a function. I prefer the second approach.function function_name {
command…
}
orfunction_name () {
command…
}
To call a function with arguments:function_name " a r g 1 " " arg1" " arg1""arg2"The function refers to passed arguments by their position (not by name), that is $1, $2, and so forth. $0 is the name of the script itself.Example:function_name () {
echo “Parameter #1 is $1”
}
Also, you need to call your function after it is declared.#!/usr/bin/env sh
foo 1 # this will fail because foo has not been declared yet.
foo() {
echo “Parameter #1 is $1”
}
foo 2 # this will work.Output:./myScript.sh: line 2: foo: command not found
Parameter #1 is 2
参数解析
https://unix.stackexchange.com/questions/129391/passing-named-arguments-to-shell-scripts
脚本在服务启动报错code=exited status=203 EXEC
手动执行脚本没问题 做成系统服务就会报错
解决办法在启动脚本加入#!/bin/bash
稳一点的话还可以加入source /etc/profile