http://blog.csdn.net/shuanghujushi/article/details/51298672 在bash shell的使用过程中,经常会遇到一些字符串string的操作,下面是个人的一些使用总结. 一.字符串的定义 用双引号,单引号,或者直接在接在=后,都可以定义一个字符串,如下,定义了三个字符串 str1="this is a string" str2='this is a string' str3=this_is 但双引号和单引号,在bash中还是有区别的
最近发现使用 -z 和 -n 来判断字符串判空,或不空时,很不靠谱. 使用下面的方法最可靠: if [ "x${value}" == "x" ] #为空 then #为空处理 fi if [ "x${value}" != "x" ] #不为空 then #不为空处理 fi 转自 Shell脚本中字符串判空:使用-z 字符串长度为0时,为真,-n字符串长度不为0,为
date的详细用户可以参考下面的 http://www.cnblogs.com/xd502djj/archive/2010/12/29/1919478.html date 的具体用法可以查看另外一篇博文 <shell date 命令详解>http://blog.csdn.net/runming918/article/details/7223520 date +%s 可以得到UNIX的时间戳;用shell将时间字符串与时间戳互转: date -d "2010-10-18
SHELL脚本编程-字符串处理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.字符串切片 [root@node101.yinzhengjie.org.cn ~]# echo {A..Z} A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# echo {A..Z}|tr -d
转自:http://blog.csdn.net/linfeng999/article/details/6661233 1. 构造字符串 直接构造 STR_ZERO=hello #shell中等号左右的空格不能随便加,如果写作STR_ZERO = hello,linux会认为STR_ZERO是一个命令而执行出错 STR_FIRST="i am a string" STR_SECOND='success' USER_NAME='world' 重复多次 #repeat the first p
在书写linux shell 脚本我们经常会遇到,对一个字符串是否为空进行判断,下面我对几种常用的方法进行了一个总结: 1.-z判断 -z string True if the length of string is zero. 实例: if [ -z $i ] then echo "$i 是空字符串" fi 2.加一个字符串再比较 if [ X$STR = "X" ] then echo "空字符串" fi 3.直接使用变量判断 if [ &q
Shell 在写函数的时候,有时候需要传递字符串,由于字符串中有空格,所以结果总是不对,下面写个小例子,解决这个问题: #!/bin/bash # value init TT="adb shell ls -l /data/local/tmp/"; FINAL=""; loop_count=2; # LoopEx: excute a programm in a loop, $1 is program,$2 is loop count, function LoopEx(