Linux Programming Bible(1)
来源:互联网 发布:js双日历农历插件 编辑:程序博客网 时间:2024/05/18 12:41
/*codestart*/
#!/bin/bash
function CountMatches {
echo -n "Number of matchs for $1:"
ls $1 2>/dev/null |wc -l
}
CountMatches /dev/sda*
CountMatches /proc/*
/*codeover*/
输出:
Number of matchs for /dev/sda:1
Number of matchs for /proc/1:36
*function函数的使用
*输出的结果并不是我们所需的,这涉及到shell编程中的引用,在 echo -n "Number of matchs for $1:" 中$1直接引用 /dev/sda* 中的第一个 即/dev/sda,同样 /proc/*的第一个 /proc/1
*修改要得到结果,在/proc/* 加单引号
*双引号与单引号的区别:双引号屏蔽大部分的meta,保留部分$等等的含义,单引号屏蔽一切meta (meta:具有特殊意义的保留字)
CountMatches ‘/dev/sda*’
CountMatches ’/proc/*‘
即
/*codestart*/
#!/bin/bash
function CountMatches {
echo -n "Number of matchs for $1:"
ls $1 2>/dev/null |wc -l
}
CountMatches ‘/dev/sda*’
CountMatches ’/proc/*‘
/*codeover*/
输出:
Number of matchs for /dev/sda*:7
Number of matchs for /proc/*:5938
用ls命令查看
[root@huangfeng sandbox]# ls /dev/sda* 2>/dev/null |wc -l
7
[root@huangfeng sandbox]# ls /proc/* 2>/dev/null |wc -l
5938
一些基础知识
标准输入 stdin 0
标准输出 stdout 1
标准错误 stderr 2
$$ 当前bash的linux进程ID
$0 保存当前进程的脚本名
$PPID 父进程ID
$RANDOM 产生随机数
$SECONDS 当前shell调用起以秒计算的时间
- Linux Programming Bible(1)
- Linux Programming Bible(2)
- Java Database Programming Bible
- XML Programming Bible
- Java Database Programming Bible
- Palm OS Programming Bible
- Linux Bible
- Linux Database Bible (Bible (Wiley))
- Ubuntu Linux Bible
- Wiley - Ubuntu Linux Bible
- SUSE Linux 10 Bible
- Linux Bible 2006
- Linux Troubleshooting Bible
- Ubuntu Linux Bible
- DirectX 3D Graphics Programming Bible
- Bible
- linux bible 第一章 硬件基础
- linux bible 第十三章 处理器
- 热门存储技术分析之SAS简介篇
- 根据汉字获取全拼
- tomcat 5.5连接池配置方法
- Mac OS X: 系统通知软件
- boost多位数组
- Linux Programming Bible(1)
- Micro Framework Interop功能实现
- 英文版操作系统下魔兽争霸
- openflashchart使用时的须注意的几个小地方
- 软件规化
- asp相关总结
- 容心工作室
- strut2 action传递参数注意点
- boost的operators