Chinaunix首页 | 论坛 | 博客
  • 博客访问: 630708
  • 博文数量: 1008
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 5175
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-31 09:44
文章分类
文章存档

2012年(1008)

我的朋友

分类:

2012-08-01 11:35:31

原文地址:shell编程 作者:luozhiyong131

#!/bin/sh

#echo something

echo "hello world"

echo "hello !!"

mkdir /tnt

 

#!/bin/sh

#set varible a

a="hello world"

#print a

echo "A is:"

echo $a

 

#!/bin/sh

#set varible num

num=2

echo "this is the ${num}nd"

 

#!/bin/sh

echo "number of vars:"$#

echo "values of vars:"$*

echo "value of var1:"$1

echo "value of var2:"$2

echo "value of var3:"$3

echo "value of var4:"$4

 

#!/bin/sh

hello="var1"

echo $hello

function func1 {

      local hello="var2"

      echo $hello

}

func1

echo $hello

 

#!/bin/sh

folder=/home

[ -r "$folder" ] && echo "Can read $folder"

[ -f "$folder" ] || echo "this is not file"

 

#!/bin/bash

for day in Sun Mon Tue Wed Thu Fri Sat

do

      echo $day

done

 

#!/bin/bash

for day in "Sun Mon Tue Wed Thu Fri Sat"

do

      echo $day

done

 

#!/bin/bash

echo "Hit a key, then hit return."

read Keypress

case "$Keypress" in

      [A-Z] ) echo "Uppercase letter";;

      [a-z] ) echo "Lowercase letter";;

      [0-9] ) echo "Digit";;

      * ) echo "Punctuation, whitespace, or other";;

esac

 

两数进行比较

#!/bin/sh

 

a=$1

b=$2

 

if [ -z $1 ] || [ -z $2 ]

then

      echo "please enter 2 no"

      exit 1

fi

 

if [ $a -eq $b ];then

      echo "a=b"

else if [ $a -gt $b ]

      then

           echo "a>b"

      elif [ $a -lt $b ]

      then

           echo "a

      fi

fi

 

 

计算当前目录下文件的个数

#!/bin/sh

counter=0

for files in *

do

      if [ -f "$files" ]

      then

           counter='expr $counter + 1'

      fi

done

echo "there are $counter files in 'pwd'"

 

 

倒序输出

#!/bin/sh

echo -n "please enter number"

read n

sd=0

rev=""

on=$n

echo "you put number is $n"

 

while [ $n -gt 0 ]

do

      sd=$(($n % 10))

      n=$(($n / 10))

      rev="$rev$sd"

done

 

echo "$on is a reverse order $rev"

 

 

文件监视

#!/bin/sh

if [ "$1" = "" ]||[ "$2" = "" ]

then

      echo "please enter file name"

      exit 1

fi

 

if [ -e $2 ]

then

      echo "the file already exists"

      until [ ! -f $2 ]

      do

           sleep 1

      done

      echo "the file have been deleted"

fi

 

if [ !'mv $1 $2' ]

then

      echo "mv sucessful"

else

      echo "error"

fi

 

 

阅读(151) | 评论(0) | 转发(0) |
0

上一篇:文件编程

下一篇:简单Makefile

给主人留下些什么吧!~~