Chinaunix首页 | 论坛 | 博客
  • 博客访问: 836902
  • 博文数量: 489
  • 博客积分: 475
  • 博客等级: 下士
  • 技术积分: 3087
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 16:28
文章分类

全部博文(489)

文章存档

2013年(7)

2012年(301)

2011年(181)

分类:

2011-12-22 20:52:22

原文地址: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

 

 

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

上一篇:文件编程

下一篇:根文件系统制作

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