Shell
shell 相关总结
elihe2011
Golang, Python, Docker, K8S
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
时间戳
1. date# current time[root@localhost ~]# date +%s1433568941[root@localhost ~]# date -d "@1433568941" "+%F %H:%M:%S"2015-06-05 22:35:41# convert date-time to timestamp[root@localhost ~]# date -d "原创 2015-06-06 14:28:34 · 299 阅读 · 0 评论 -
for & while 的不同
参考:http://www.jb51.net/article/79002.htm#!/bin/bash# while loopecho -en "\t";datecat abc.txt|while read user ipdo{ ssh -oConnectTimeout=10 $user@$ip "hostname" < /dev/null sleep 10s} &don转载 2016-03-21 23:20:11 · 346 阅读 · 0 评论 -
shell数组
1. seq [FIRST [INCREMENT]] LAST -s: –separator=STRING -w: –equal-widthseq -s'#' 1 20 | sed 's/[0-9]*//g'seq -w 1 10 1002. list & arraylist=$(seq 100)list=$(echo {1..100}) # more efficientarray=($(s原创 2016-03-21 23:21:53 · 220 阅读 · 0 评论 -
随机数
1. $RANDOM[root@localhost ~]# echo $RANDOM18657[root@localhost ~]# echo $RANDOM277542. /dev/urandom[root@localhost ~]# head -1 /dev/urandom | cksum69246905 784[root@localhost ~]# head -1 /dev/ura原创 2015-06-06 14:53:56 · 951 阅读 · 0 评论 -
通配符与元字符
1. wildcard*?[c1-c2][!c1-c2]{str1,str2,...,strN}2. MetaIFS <space>, <tab>, <enter>CR <enter>=$> stdout redirect< stdin redirect|& redirect to file descriptor; run a program in backgro原创 2016-03-21 23:25:14 · 559 阅读 · 0 评论 -
IO重定向
I/O Redirection: > filename # The > truncates file "filename" to zero length # If file not present, creates zero-length file (same effect as 'touch'). # The : serves as a原创 2016-03-21 23:29:10 · 335 阅读 · 0 评论 -
字符串处理
字符串长度(String Length)${#string}expr length $stringexpr "$string" : '.*'匹配的最小子串的长度(Length of Matching Substring at Beginning of String)expr match "$string" '$substring' # $substring is a regul原创 2016-03-21 23:34:42 · 412 阅读 · 0 评论 -
sh(bsh)
1. Initialize /etc/profile .profile2. Prompt PS1($): the primary prompt PS2(>): the secondary promptPS1=”uname -n >” PS2=”—–>”3. variable# local variablename="Tom"# global variableexport ORACLE原创 2016-03-21 23:39:36 · 635 阅读 · 0 评论 -
csh(tcsh)
1. TC Shell Initialize /etc/csh.cshrc /etc/csh.login .cshrc2. Prompt# The primary prompt set prompt = "$LOGNAME > "# The secondary prompt?3. Variable# local variableset name = "Tom"# global varia原创 2016-03-21 23:45:05 · 1148 阅读 · 0 评论 -
ksh
1. startup The first process: initinit -> getty -> login -> kshinitialization file: .profile environment file: .kshrc # export ENV=.kshrc2. environment /etc/profile -> .profile -> .kshrc3. Va原创 2016-03-21 23:52:24 · 789 阅读 · 0 评论 -
条件测试
类型 [ ] [[ ]](ksh/bash, keyword) (()) 数字测试 -eq -ne -lt -le -gt -ge 同[] >, >=, <, <=, ==, != 文件测试 -r -l -w -x -f -d -s -nt -ot 同[] NA 字符串测试 = != -n -z 同[] NA 字符串测试(>, <)原创 2016-03-21 23:04:47 · 319 阅读 · 0 评论 -
特殊变量
$$ Shell本身的PID$! 最后运行的后台进程的PID$? 最后运行的命令的返回值$- 使用set命令设定的Flag一览 $* 所有参数列表。"$*"输出为"$1 $2 … $n" $@ 所有参数列表。"$@"输出为"$1" "$2" … "$n" $# 参数个数 $0 Shell本身的文件名 $1~$n 各参数值原创 2016-03-21 22:41:01 · 279 阅读 · 0 评论 -
多行变一行
xargs xargs < myfilevariable a=$(cat myfile); echo $atr tr -s ‘\n’ ’ ’ < myfilesed sed -n ‘1h;1H;${g; s/\n//g; p;}’ myfile sed ‘:a; N; s/\n//; ta;’ myfileawk awk ‘{printf(“%s “, $0);}END{prin原创 2015-06-05 22:16:55 · 555 阅读 · 0 评论 -
信号和trap
1. 信号:那些被异步发送到一个程序的事件# trap -l 1) SIGHUP 终止进程,终端线路挂断 2) SIGINT 终止进程,中断进程(Ctrl-C) 3) SIGQUIT 终止进程,产生core文件(Ctrl-) 4) SIGILL 非法指令 9) SIGKILL 终止进程,杀死进程 15) SIGTERM 终止进程,软件终止信号 18) SIGCO原创 2016-03-02 21:50:54 · 353 阅读 · 0 评论 -
Shell Debug
适合ksh, bash1. 使用trap命令# 追踪命令或函数的返回状态trap 'echo "[LINE:$LINENO] Error: Command or function exited with status $?"' ERR# 追踪命令执行后的详细结果trap 'echo "Before execute line $LINENO: a=$a, b=$b, c=$c"' DEBUG2.原创 2016-03-02 21:55:34 · 326 阅读 · 0 评论 -
交互式SHELL和非交互式SHELL、登录SHELL和非登录SHELL的区别
转载:http://smilejay.com/2012/10/interactive-shell-login-shell/曾经写过“交互式shell和非交互式shell、登录shell和非登录shell的区别”,但那时理解相对更浅一些,现在多了一点认识,把这篇文章稍微完善一下吧。交互式shell和非交互式shell、登录shell和非登录shell的区别。 首先,这是两个不同的维度来划分的,一个是转载 2016-03-17 12:41:01 · 377 阅读 · 0 评论 -
隐藏oracle命令行登陆密码
命令行隐藏数据库用户名和密码#!/bin/kshheading=onSYSTEM_CONNECT="dbname/dbpass"$ORACLE_HOME/bin/sqlplus -s /nolog <<!!set line 200set feedback offset heading ${heading}connect ${SYSTEM_CONNECT};column global_na原创 2016-03-18 19:13:51 · 499 阅读 · 0 评论 -
stty 终端环境设置
intr 发送中断信息(ctrl-c) quit 发送退出信号(ctrl-\) erase 向前删除字符(delete) kill 删除整行命令(ctrl-u) eof 文件结束(ctrl-d) start 重启暂停的输出(ctrl-q) stop 停止当前输出(ctrl-s) susp 发送终端停止信号(ctrl-z) rprnt 输入命令原创 2016-02-23 22:49:32 · 402 阅读 · 0 评论 -
数学计算
1. bc:An arbitrary precision calculator language scale: decimal arithmetic ibase/obase: decimal/binary/octal/hexadecimalmath library: bc -l, –mathlib s(x) # sine c(x) # cosine a(x) # arctangen原创 2016-02-23 23:01:16 · 463 阅读 · 0 评论 -
eval
两次扫描,第一次变量替换,第二次执行命令1. 获取最后一个参数eval echo \$$#2. 指针x=100px=xeval echo \$$px # echo $xeval $px=50 # x=503. 变量替换v1=aaavaaa="This is aaa"eval $v1=$vaaa # aaa=This is aaa 错误eval $v1="$vaaa原创 2016-02-23 23:10:03 · 1996 阅读 · 0 评论 -
变量替换
1. 变量替换并赋值 := 变量已声明,但取值为空 = 变量未声明username=""echo ${username:=$LOGNAME} # usr_insecho $username # usr_insunset usernameecho ${username=$LOGNAME} # usr_insecho $usern原创 2016-03-21 22:38:33 · 397 阅读 · 0 评论 -
bash array
1. declaredeclare -a arrayread -a array < input.txt2. assignmentarray[key]=valuearray=(val1 val2 ... valN)3. access# the first element${array[0]} <=> ${array[@]:0:1} <=> $array# the entire elements原创 2015-07-01 22:04:47 · 400 阅读 · 0 评论
分享