Chinaunix首页 | 论坛 | 博客
  • 博客访问: 120504
  • 博文数量: 25
  • 博客积分: 1436
  • 博客等级: 上尉
  • 技术积分: 256
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-17 10:10
文章分类

全部博文(25)

文章存档

2016年(1)

2015年(5)

2012年(1)

2011年(3)

2010年(6)

2009年(8)

2008年(1)

我的朋友

分类: LINUX

2009-04-21 14:43:48

I. 更改html form 传过来的乱码路径




截取带绝对路径的文件名。
-----------------------------------
ss="/home/alexliu/data/a.torrent"
echo ${ss##*/}
a.torrent
-----------------------------------
ss="E:\home\alexliu\data\a.torrent"
echo ${ss##*\\}



II. Shell 字符操作

1. 得到长度
x="abcd"
方法一:expr length $x 方法二: expr "$x" : ".*"

2. 查找子串的位置
x="abcd"
expr index $x "b"

3. 得到子串
x="abcdefgh"
expr substr "$x" 2 6 结果是:bcdef

4. 截取
方法一:
echo $a|cut -d',' -f3
cut:对标准输入的字符串进行处理
cut -bn-m:以byte为单位,从第n个byte开始,取m个
cut -bn,m:以byte为单位,截取第n,m个byte
cut -b-n,m:以byte为单位,截取1-n,和第m个
-c:以charactor为单位
-d:指定分隔符,默认为tab
-s:使标准输入中没有delimeter
cut -f1:截取第1个域
方法二:
expr substr “$a” 1 8 # 截取$a中的1到8个字符。
方法三:
${varible##*string} 从左向右截取最后一个string之后的字符串。
${varible%%string*} 从右向左截取最后一个string之后的字符串。
${varible#*string} 从左向右截取第一个string之后的字符串
${varible%string*} 从右向左截取第一个string之后的字符串

5. 在需要长时间才能打开的网页中加载一段loading进度条的代码。

Loading...









III.shell 中固定次数的for循环。
n=10
for i in `seq $n`
do
echo "$i"
done

IV. eval 函数可以把两字符串重组然后再变成一个变量。
a=123
b=-----------2345
eval temp=$a$b
zhong123=adsfjsdgjsdjfgjksldjf
eval temp1="zhong"$a
eval temp2="$zhong"$a
eval temp3="$""zhong"$a
echo $temp //结果是:123-----------2345
echo "$temp1" //结果是:zhong123
echo "$temp2" //结果是:123 因为$zhong不存在。所以结果只有$a的值。
echo "$temp3" //结果是:adsfjsdgjsdjfgjksldjf 这正是我想要的结果。


V. shell's commands
sed 's@^/lib/ld-linux.so.2@/tools&@g' ### "@" is a separate symbol.
sed 's:/usr/local/bin:/bin:' configure.bak > configure ### ":" is a separate.
cp configure{,.bak} ### cp configure configure.bak
mv configure{,.bak} ### mv configure configure.bak
sed -e "$"d ### remove the last line.
$ sed -n 's/^test/mytest/p' example-----(-n)选项和p标志一起使用表示只打印那些发生替换的行。也就是说,如果某一行开头的test被替换成mytest,就打印它。
$ sed 's/^192.168.0.1/&localhost/' example-----&符号表示替换换字符串中被找到的部份。所有以192.168.0.1开头的行都会被替换成它自已加 localhost,变成192.168.0.1localhost。


VI. PERL
用perl写html是在#!/usr/bin/perl之后一定要加入print “Content-type:text/html\n\n”;这句话.如下:
#!/usr/bin/perl
Print “Content-type:text/html\n\n”;

VII. sed 实例
1. 替换文件中的内容。
path=\/usb1-disk1\/Download\/Bt
a=$(sed -n "/Btstorepath=/=" usbnas.conf)
sed -i -e "$a i\Btstorepath=$path" -e "$a"d usbnas.conf

2. 替换文件中的内容。
sed -i "s/runbtdownload.*/runbtdownload=yes/" usbnas.conf
sed -i "s|Btstorepath=.*\(.*\)|Btstorepath=\1$path|" usbnas.conf
sed -i "s|$variable=.*\(.*\)|$variable=\1$value|" usbnas.conf
阅读(564) | 评论(0) | 转发(0) |
0

上一篇:UShare-1.1a 编译

下一篇:samba configure

给主人留下些什么吧!~~