
shell
dhz120
这个作者很懒,什么都没留下…
展开
-
shell中函数返回的问题
运行结果:由此可以看出,$?可以返回return的结果,而通过这种固定的方式 var=$(func),可以返回第一个echo中的值原创 2013-08-21 15:41:54 · 1031 阅读 · 0 评论 -
bc进制转换
#!/bin/bashif [ $# -ne 3 ]then echo "`basename $0` " exitfiin=$1out=$2num=$3result=`echo "obase=$out; ibase=$in; $num" | bc`echo "result is $result"原创 2014-12-02 18:55:17 · 1257 阅读 · 0 评论 -
根据date创建目录
#!/bin/bash#file name : today.sh# 今天的日期,格式为:091814today=`date "+%D" | tr -d '/'`echo "today is $today"# 目录不存在就创建[ ! -e $today ] && mkdir $today# 进入到today目录cd $today原创 2014-09-18 10:48:32 · 864 阅读 · 0 评论 -
找到最新的文件,然后建立软链接
#!/bin/bash#找到最新的文件latest_file=`ls -t | head -1`#echo $latest_file#为最新的文件建立软链接ln="latest"[ -a $ln ] && rm $lnln -s $latest_file $ln原创 2014-09-17 23:26:59 · 1153 阅读 · 0 评论 -
用脚本下图片
#!/bin/bashif [ $# -ne 1 ]then echo "`basename $0` " exitfiurl=$1img=`curl -s $url | egrep -o "]*>" \ | sed 's/<img src=\"\([^"]*\).*/\1/g'`# 以baidu为例,搞出来的结果是 //www.baidu...., ${原创 2014-09-25 19:15:10 · 749 阅读 · 0 评论 -
shell find->while
#!/bin/bashwhile read linedo echo $linedone将find搜索的原创 2014-09-23 19:12:31 · 2404 阅读 · 0 评论 -
几个简单shell Demo
1.解压#!/bin/bash #实现对一下几种文件的解压: *.zip *.tar *.tar.gzftype="$(file "$1")"case "$ftype" in "$1: Zip archive"*) unzip "$1" ;; "$1: Gzip compressed"*) gunzip "$1" ;; "$1: POSIX tar"*) ta原创 2013-08-13 13:49:45 · 964 阅读 · 0 评论 -
shell中几个括号的总结
在Shell中的小括号,大括号结构和有括号的变量,命令的用法如下:1.${var}2.$(cmd)3.()和{}4.${var:-string},${var:+string},${var:=string},${var:?string}5.$((exp))6.$(var%pattern),$(var%%pattern),$(var#pattern),$(v转载 2013-08-13 11:46:46 · 852 阅读 · 0 评论 -
grep -q的用法
grep -q用于if逻辑判断 突然发现grep -q 用于if 逻辑判断很好用。 -q 参数,本意是 Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an error was dete转载 2013-08-21 16:14:10 · 61782 阅读 · 3 评论 -
往文件第一行插入内容
#!/bin/bashif [ $# -ne 2 ]then echo "Usage `basename $0` " exitfistr=$1file_name=$2echo "$str" | cat - $file_name > /tmp/var.$$mv /tmp/var.$$ $file_namee.g. 比如往一堆java文件中添加pack原创 2014-12-08 19:23:41 · 3587 阅读 · 0 评论