SHELL 学习
来源:互联网 发布:社保报盘软件下载 编辑:程序博客网 时间:2024/06/06 14:25
Date
$ date2014年11月19日 星期三 21时16分17秒 CST$ date +%s1416402983$ date "+%d %B %Y"19 十一月 2014$ start=$(date +%s)$ echo $start1416403040$ end=$(date +%s)$ echo $end1416403066$ diff=$((end-start))$ echo $diff26
Alias
usage: alias new_command='command sequence'
delete: unalias or alias example=
note: only available for current session
overwrite if alias is already existing
Array (available from bash 4.0)
arry=(1 2 3 4 5)echo $arry[*]1[*]echo ${arry[*]}1 2 3 4 5echo ${arry[@]}1 2 3 4 5echo ${arry[2]}3index=3echo ${arry[$index]}4#print length of arrayecho ${#arry[*]}5arry_var[0]="danio"arry_var[1]="mia"arry_var[3]="bing"echo ${arry_var[*]}danio mia bingecho ${arry_var[1]}miaecho ${#arry_var[*]}3
输入输出重定向
0 - stdin
1 - stdout
2- stderr
$?查看命令执行是否成功 0 - 成功, 非0 - 失败
ls ! 2>err.txt 1>out.txtcat err.txtls: !: No such file or directorycat out.txtecho $?0ls !ls: !: No such file or directoryecho $?1
#covert stderr to stdout and redirect to log.txt file by using 2>&1 or &>ls ! 2>&1 log.txtls: !: No such file or directorylog.txtcat log.txtls: !: No such file or directoryls ! &>log2.txtcat log2.txtls: !: No such file or directory
</pre><pre name="code" class="python"><pre name="code" class="python">#cleanup stderrls ! 2>/dev/null
#tee accept stdout only and will pass them to next command# following command display current folders and files, and save to out.txt, then cat -n add line number for each input from stdout.ls | tee out.txt | cat -n# use -a if tee append to file but not overwritels | tee -a out.txt | cat -n
bc 数学高级运算
echo "4 * 5.5" | bc#output 22.0no=1000echo "obase=2;$no" | bc#output 1111101000echo "scale=3; 3/7" | bc#output .428 (keep 3 points)echo "sqrt(10000)" | bcecho "100^2" | bc#output:#100#10000
let, [], 整形运算
num1=2;num2=4;let result=num1+num2echo $result#output 6
let num1++
echo $num1
#output 3
num1=2;num2=4;result=$[num1+num2]echo $result#output 6
</pre><pre name="code" class="javascript"><pre name="code" class="javascript">var=100let result=var*10echo $result1000result1=$[var*100]echo $result110000
$[ var1:+var2]如果var1不为空则使用vare.g.
var1=abcvar2=defvar3=${var1:+$var1$var2}echo $var3
output is "abcdef"
export PATH="$PATH:/home/user/bin"
将/home/user/bin加入PATH环境变量中,当前的terminal session有效
echo $SHELL
/bin/bash
识别当前使用的 shell
$UID 是否为0来判断是否为root用户
if [ $UID -ne 0 ]; then echo "non root user"else echo "root user"fi
0 0
- shell学习
- shell 学习
- shell学习!
- 学习shell
- shell学习
- shell学习
- shell学习
- shell学习
- 学习shell
- Shell 学习
- shell学习
- shell 学习
- shell学习
- shell 学习
- shell学习
- shell 学习
- SHELL 学习
- shell学习
- java 实践源码--并查集
- HDU 3812
- nike aRBI HMj Tq3Qm
- 读黑客与画家,吐槽的一些话——中国科学技术大学软件+冯开开+原创
- 通过show status 来优化MySQL数据库
- SHELL 学习
- 解决:centos 虚拟机上安装apache后,不能访问
- python的入门注意
- Android Animation动画(超详细)
- 2014秋C++第12周项目2参考-OJ平台题目中多种输入形式的处理
- codeforces455A Boredom (裸DP)
- javascript 面向对象深入学习-----(一)
- Delphi INI 文件读写
- 结构类型变量的引用