Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7688889
  • 博文数量: 961
  • 博客积分: 15795
  • 博客等级: 上将
  • 技术积分: 16612
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 14:23
文章分类

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类:

2010-12-06 19:43:23

#!/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

 

 

阅读(1046) | 评论(0) | 转发(3) |
0

上一篇:简单Makefile

下一篇:文件编程

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