随笔分类 -  Bash

linux commands line and shell program
一些 shell 代码
摘要:1. 计算当前脚本目录下的文件个数。 1 #!/bin/sh 2 # 3 4 counter=0 5 for file in * 6 do 7 counter=`expr $counter+1` 8 done 9 10 echo "There are $counter files in `pwd`"2. 将 .foo 后缀的文件批量改名为 .bar 后缀。#!/bin/sh#for f in *.foodo base=`basename $f.foo` mv $f $base.bardone3. 将大写文件名改为小写文件名。1 #!/bin/bash2 #3 4 for f 阅读全文
posted @ 2011-04-03 21:31 oyzway 阅读(794) 评论(0) 推荐(0)
Shell 入门基本知识 __ 第二部分
摘要:5. 条件控制:有时需要判断字符串是否相等,需要判断文件状态,对数字进行测试。对文件、字符串和数字使用 test 命令;对数字、字符串还可使用 expr 命令。命令格式: $test condition 或: [ condition ] 注意 []与条件必须有空格。5.1. 文件状态测试:test 状态 或 [ 状态 ] 1 [ -e file ] 文件存在 2 [ -d directory ] 目录存在 3 [ -s file ] 文件大小大于0 4 [ -r file ] 文件可读 5 [ -b file ] 区块文件 6 [ -c file ] 字符文件 7 [ -f file ] 一般 阅读全文
posted @ 2011-04-03 21:10 oyzway 阅读(1334) 评论(0) 推荐(0)
Shell 入门基本知识 __ 第一部分
摘要:1. 简介: Shell 是一种接口程序,用户可以通过它可以与 Unix/Linux 操作系统的核心程序进行交互。Bash 即 Bourne again shell ( /bin/bash )。Shell 程序相当于 dos 的批处理文件,一条命令就可以完成某项任务,也可以通过循环、条件控制、数学运算、文件测试、传递参数等方式完成复杂的管理任务。它提供个人化的用户环境,在 shell 的初始化文件 ( .profile, .login, .cshrc, .tcshrc 等)中完成,这些文件包括设置终端机键盘,定义窗口的特征,设置变量,定义查找路径,许可权限,提示符号和终端型以及设置特殊应用程序 阅读全文
posted @ 2011-04-03 17:03 oyzway 阅读(3255) 评论(0) 推荐(1)
Linux Command Line and Shell Scripting Bible__第11章
摘要:Linux Command Line and Shell Scripting Bible__第11章第11章 处理用户输入向shell脚本传递数据的最基本方式是使用:命令行参数。位置参数:$0为程序名称,$1为第一个参数,$2为第二个参数,……直到$9为第9个参数。第9个变量之后,必须使用大括号将变量括起来,如${10}。读取程序名称:传递给变量$0的字符实际上是程序的... 阅读全文
posted @ 2010-09-16 19:27 oyzway 阅读(624) 评论(0) 推荐(0)
Linux Command Line and Shell Scripting Bible__第10章
摘要:Linux Command Line and Shell Scripting Bible__第10章第10章 更多结构化命令-----------for-----------[代码]内部字段分隔符IFS(internal field separator) bash shell默认将 空格、制表符、换行符 看作字段分隔符。如果想将IFS的值更改为只识别换行符,需要这样做:IFS=$'\n'警告:当使... 阅读全文
posted @ 2010-09-14 17:47 oyzway 阅读(660) 评论(0) 推荐(0)
Linux Command Line and Shell Scripting Bible__第9章
摘要:str1 = str2 str1与str2是否相同 str1 != str2 str1与str2是否不同 str1 str2 str1是否大于str2 -n str1 str1长度是否大于0 -z str1 str1长度是否为0 阅读全文
posted @ 2010-09-12 14:45 oyzway 阅读(312) 评论(0) 推荐(0)