您的位置:首页 > 运维架构 > Shell

shell脚本应用(5)--实用脚本片段

2014-02-26 21:29 429 查看
校验参数


if [ "$#" -ne 1 ]

then

echo "Incorrect number of arguments"

echo "Usage: command arg1"

exit 1

fi



等待后台程序执行完再继续


prog1 &

#获取prog1的pid

pid1 = $1

...

#等待后台prog1执行完继续脚本

wait &pid



提示用户输入参数


#!/bin/bash

read -p "please type the password:" PW

echo $PW



更改登录用户密码,懒得每次输入新旧密码


#!/bin/bash

(echo "curpw"; sleep 1; echo "newpw"; sleep 1; echo "newpw") | passwd



ACM用测试数据检验程序正确与否


#!/bin/bash

while true

do

#生成随机变量到input文件中,r可以是生成脚本

./r > input

./a < input > output.a

./b < input > output.b

diff output.a output.b

if [ $? -ne 0 ]

then

break

fi

done

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: