bah 带你入门

我们经常会在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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值