-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bash shell #40
Comments
基本语法注意空格, name=hello
name+=' world' # hello world
count=1
count+=1 # 11 字符串拼接
count=1
let "$var+=1" # 2 此时是数学运算
((count++)) # 数学运算 if控制流条件判断里, 用
http://tldp.org/LDP/abs/html/tests.html if ....; then
expr
elif ...; then
expr
else
expr
fi 与and 或or与或要分两种场景
test -f some_file -a -d some_dir
# 等同于
[ -f some_file -a -d some_dir ]
# 在一个测试表达式中使用 `-a` 表示与, 同时满足 2.在一个 if 判断中 if [ -f some_file ] && [ -d some_directory ]; then
echo "Well"
fi forfor var in A B C; do
echo $var
done while & untilwhile ...; do
expr
done
select var in A B C ; do
break;
done
$var = A | B | C
case var in
case1)
expr;;
case2)
expr;;
esac |
特殊符号
|
命令行参数
$1 # 第一个命令行参数 arg1
$@ # 所有参数, for var in $@ 可以循环取出
$* # 所有参数, 但是 for in $* , 只会执行一次, 值是全部的值 运行 #!/usr/bin/env sh
split(){
echo "-----------------"
}
for x in $@; do
echo $x
done
split
for x in "$@"; do
echo $x
done
split
for x in $*; do
echo $x
done
split
for x in "$*"; do
echo $x
done 结果
|
函数上面用了一个简单的
|
有程序的exit code > 0, 就立即退出 |
Unix 系 alias v.s function
mnpm(){
npm \
--registry=http://r.npm.sankuai.com \
--cache=$HOME/.cache/mnpm \
--disturl=https://npm.taobao.org/dist \
--userconfig=$HOME/.mnpmrc \
$@
}
|
export declare typesethttp://linux.die.net/man/1/zshbuiltins
查看全局变量
更多资料
|
Shell 脚本学习指南 |
入门2.5.5.1 重定向与管道
2.5.5.2两个特殊文件
if grep pattern myfile > /dev/null; then
echo "found."
else
echo "Go Away"
fi
看不懂... 2.5.6 PATH环境变量
PATH环境变量中的空白, 同 # 第一个是 `:` 于是第一部分就是空白
PATH=:/usr/bin/:/usr/local/bin
# 中间有空白, `::`
PATH=/usr/bin::/usr/local/bin 建议使用 2.6 argv命令行参数 $1 # 第1个命令行参数
$9 # 第9个
${10} # 第10个 |
3 查找与替换grepgrep = g/ re /p = 全局性匹配 re ,并将其打印 usage:
3.2
|
6env
unset
# 删除变量, 默认 -v
unset -v var_name
unset var_name
# 删除函数
unset -f fn_name 6.1.2 参数展开
特殊变量
6.2.1 Exit Status
6.5 函数fn_name(){
# $0 - $9 变成了形参
# return 同 exit
}
# 调用函数并存储结果
x=$(fn_name 参数) |
7重定向0,1,2 分布代表 stdin, stdout, stderr # 将stdout输出至out.log, 将stderr输出至err.log
program 1> out.log 2> err.log
# 将stderr重定向至stdout
# `2>&1` 要在 `>out.log` 之后
# shell处理重定向时, 从左至右, 2>&1时发现 `&1`
# 是console, 则输出console
# 是out.log, 则输出是out.log
program >out.log 2>&1 7.5 通配符
dirname & basename同 node.js 里 path.dirname & path.basename $ basename ch2/dev-tty.sh
dev-tty.sh
$ basename ch2/dev-tty.sh ".sh"
dev-tty
$ basename ch2/dev-tty.sh sh
dev-tty. |
date
|
psOSX
Linux |
xargsxargs [options] [command] command 默认是 options
|
crontabhttp://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/crontab.html 第一列 第二列 第三列 第四列 第五列 |
ln
src: 已经存在的文件, 箭头右边 shell script path
|
flag list
args=(
--app-icon '/Applications/Platypus.app/Contents/Resources/PlatypusAppIcon.icns'
--interface-type 'Text Window' --text-font 'Jetbrains Mono 16'
--author 'magicdawn'
--interpreter '/bin/zsh'
--optimize-nib
--overwrite
)
platypus "${args[@]}" \
--quit-after-execution \
--name "<name here>" \
--interpreter-args $'-c|set -x; <cmd here>' \
"$(dirname "$0")/default.sh" "$HOME/Applications/Platypus/<app name here>.app" |
Things about bash shell.
And GNU Make see #26
resources
The text was updated successfully, but these errors were encountered: