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

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类: 嵌入式

2010-09-10 21:27:37

Linux系统管理    http://blog.chinaunix.net/u3/117680/showart.php?id=2320993

 

 

 

Hello:

 

#!/bin/sh

echo "hello world"

 

 

s1:

#!/bin/sh

#set varible a

a="hello world"

#print a

echo "A is:"

echo $a

 

 

s2:

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

 

 

s3:

#!/bin/bash

hello="var1"

echo $hello

function func1 {

      local hello="var2"

      echo $hello

      }

      func1

      echo $hello

 

 

s4:

#!/bin/bash

a=$1

b=$2

if [ -z $a ] || [ -z $b ]

then

    echo "please enter 2 no"

    exit 1

fi

if [ $a -eq $b ] ; then

    echo "number a = number b"

else if [ $a -gt $b ]

    then

        echo "number a>number b"

    elif [ $a -lt $b ]

        then

            echo "number a

    fi

fi

 

 

s5:

#!/bin/sh

folder=/home

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

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

 

 

S6:

#!/bin/bash

DIR=$1 

#if  the string empty

if [ "$DIR" = " " ]

then

    echo "usage: `basename $0` directory to create" >&2

    exit 1

fi

echo "dir" $DIR

if [ -d $DIR ]

then

    echo "The directory already exist"

    exit 0

else

    echo "The directory does exist"

    echo -n "Create is now? [Y/N]:"

    read create

    if [ "$create" = "y" ] || [ "$create" = "Y" ]

    then

        echo "creating now"

      if [ mkdir $DIR ]

          then

DIR=" "

      fi

       

      if [ "$DIR" = " " ]

        then

           echo "create directory sucess"

        else

            echo "create directory error"

        fi

    elif [ "$create" = "n" ] || [ "$create" = "N" ]

      then

            echo "does not create directory"

            exit 0

    else

        echo "Errors order"

        exit 1

    fi

fi

 

 

s7:

#!/bin/bash

for day in Sun Mon Tue Wed Thu Fri Sat

do

      echo $day

done

 

 

s8:

#!/bin/bash

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

do

      echo $day

done

 

 

s9

#!/bin/bash

 

counter=0

for files in *

do

    counter=`expr $counter + 1`

done

echo "There are $counter files in `pwd` we need to process"

 

 

s10:

#!/bin/bash

echo -n "Pleasw enter number : "

read n

sd=0

rev=""

on=$n

echo "$n"

while [ $n -gt 0 ]

do

    sd=$(( $n % 10 )) # get Remainder

    n=$(( $n / 10 ))  # get next digit

    rev=$( echo $rev$sd )

done

echo  "$on in a reverse order $rev"

 

 

s11

#!/bin/bash

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

fi

if [ ! `mv $1 $2` ]

then

    echo "mv sucessful"

else

    echo "mv error"

fi

 

 

S12:

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

 

 

Linux系统管理    http://blog.chinaunix.net/u3/117680/showart.php?id=2320993

阅读(2104) | 评论(0) | 转发(2) |
0

上一篇:Shell编程

下一篇:GCC程序编译

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