linuxshell编程指南第二十四章------shell嵌入命令

浏览:
字体:
发布时间:2013-12-15 22:18:58
来源:

实际上已经用过了许多shell嵌入命令。可能要想什么是shell嵌入,这些命令是在实际的Bourne shell里创建而不是存在于/bin或usr/bin目录里。嵌入命令比系统里的相同命令要快。

本章内容有:

标准的Bourne shell嵌入命令列表

例如,cd和pwd命令可同时在系统和嵌入命令中发现。如果要运行系统版,简单输入命令路径即可:
/bin/pwd
/

在查看调试脚本、打开或关闭shell选项时,曾用到set命令。set也可用于在脚本内部给出其运行参数,以下举例说明。假定有一段脚本控制两个参数,但并不向脚本传递参数而是在脚本内部设置其取值。可以用set命令完成此功能。
格式为:
set param1 param2 ..

下面的脚本设置参数为accounts.doc和accounts.bak,然后对参数进行循环处理。
[root@localhost huangcd]# ./set_ex
accounts.doc
accounts.bak
[root@localhost huangcd]# cat set_ex
#!/bin/bash
set accounts.doc accounts.bak
while [ $# != 0 ]
do
echo $1
shift
done

times命令给出用户脚本或任何系统命令的运行时间。第一行给出shell消耗时间,第二行给出运行命令消耗的时间。下面是times命令的输出结果:
[root@localhost huangcd]# times
0m0.056s 0m0.125s
0m0.630s 0m0.599s

使用t y p e查询命令是否仍驻留系统及命令类型。type打印命令名是否有效及该命令在系统的位置。例如:
[root@localhost huangcd]# type mayday
bash: type: mayday: not found
[root@localhost huangcd]# type pwd
pwd is a shell builtin
[root@localhost huangcd]# type cp
cp is aliased to `cp -i'

ulimit设置运行在shell上的显示限制。通常此命令定位于文件/etc/profile中,但是可以从当前shell或用户.profile文件中将之移入用户需要的位置。ulimit一般格式如下:
ulimit options

ulimit有几个选项,以下是一些常用的选项:

选项含义

-a 显示当前限制

-c 限制内核垃圾大小

-f 限制运行进程创建的输出文件的大小
[root@localhost huangcd]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 11357
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 11357
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
[root@localhost huangcd]# ulimit -c 1
[root@localhost huangcd]# ulimit -a
core file size (blocks, -c) 1
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 11357
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 11357
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

wait命令等待直到一个用户子进程完成,可以在wait命令中指定进程ID号。如果并未指定,则等待直到所有子进程完成。

等待所有子进程运行完毕:
$ wait

>更多相关文章
24小时热门资讯
24小时回复排行
资讯 | QQ | 安全 | 编程 | 数据库 | 系统 | 网络 | 考试 | 站长 | 关于东联 | 安全雇佣 | 搞笑视频大全 | 微信学院 | 视频课程 |
关于我们 | 联系我们 | 广告服务 | 免责申明 | 作品发布 | 网站地图 | 官方微博 | 技术培训
Copyright © 2007 - 2024 Vm888.Com. All Rights Reserved
粤公网安备 44060402001498号 粤ICP备19097316号 请遵循相关法律法规
');})();