随笔分类 -  Shell编程

Linux中通过shell进行数据计算
摘要:在bash shell中可以利用let、(())和[]执行基本呢的算数运算。而在进行高级操作时,可以利用expr和bc两个工具进行计算。1、let命令可以直接执行基本的算数计算。当使用let时,变量名之前不许要再添加$。let result=num1+num2#!/bin/bash a=5 b=6 let result=a*b echo $result let result*=result #注意此行,变量与符号之间不能有空格 echo "the result is $result"结果为30the result is 9002、操作符[]的使用方法和let命令相似。res 阅读全文

posted @ 2012-06-20 00:02 无心出岫 阅读(12094) 评论(0) 推荐(0)

ATM取款机系统模拟仿真
摘要:#!/bin/shHOSTNAME="localhost" #数据库信息PORT="3306"USERNAME="root"PASSWORD=""#数据库名称DBNAME="bank" TABLENAME="user" #两个标记,用于判断是否超过输入flag=1flag1=1#输入帐号密码成功后进行接下来操作main(){echo "Please input what do you want to... 阅读全文

posted @ 2011-12-30 19:52 无心出岫 阅读(369) 评论(0) 推荐(0)

查看文件夹中的文件的修改时间,并从小到大排列出来到一个文件中
摘要:#!/bin/shecho -n "" >filefor dir in $( ls ) do time'=` date +%Y%m%d%H%M%S -r $dir ` echo "$time $dir" >>file done sort -n -k 1 file 阅读全文

posted @ 2011-11-19 19:56 无心出岫 阅读(401) 评论(0) 推荐(0)

脚本2 (监控)
摘要:#!/bin/shecho -n "Please enter the number of person from the server :"read numn=`tail -n1 shuchu` if [ $n -eq $num ] ; then echo $num >> shuchu else echo $num >shuchu fim=`wc -l shuchu|awk '{print $1}'` if [ $m -ge 5 ] && [ $m -le 20 ] ; then if [ $n -eq 0 ] then e 阅读全文

posted @ 2011-11-06 13:00 无心出岫 阅读(235) 评论(0) 推荐(0)

脚本
摘要:#!/bin/sh directory() { for file in $( ls ./qq ) do cat ./qq/$file | while read line do sed -n '/'$line'/p' ./passwd >> ./jieguo/$file done # sort /home/guo/debug |uniq > /home/guo/debug.txt done } directory 阅读全文

posted @ 2011-11-04 18:42 无心出岫 阅读(144) 评论(0) 推荐(0)

查看该目录下有几个文件夹几个文件的shell代码
摘要:#!/bin/sh directory() { let "filenum = 0 " let "dirnum = 0 " ls $1 echo "" for dir in $( ls ) do if [ -d $dir ] then let "dirnum+=1" else let "filenum+=1" fi done echo "The number of directories is $dirnum " echo "The number of files i 阅读全文

posted @ 2011-10-08 17:47 无心出岫 阅读(324) 评论(0) 推荐(0)