LinuxShell脚本编程实例

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#! /bin/sh

echo "Current command is $0"

echo "The first parameter is $1"

echo "The second parameter is $2"

echo "The third parameter is $3"

echo "Total of parameters if $#"

echo "Current PID is $$"

#!/bin/bash

times=0

until [ "$times" = 3 ];

do

echo "I love linux."

sleep 2

times=`expr $times + 1`

done

#!/bin/bash

# menu shell script. samli 2004.4.19 until

echo "List Directory..........1"

echo "Change Directory........2"

echo "Edit File...............3"

echo "Remove File.............4"

echo "Exit Menu...............5"

read choice

test $choice = 5

do

case $choice in

1) ls;;

2) echo "enter target directory:" read dir

cd $dir

;;

3) echo "enter file name:"

read file

vi $file

;;

4) echo "enter file name:"

read file

rm $file

;;

5) echo "Goodbye"

;;

*) echo "illegal option, please input again." esac

done

#! /bin/sh

var1="abcd efg"

echo $var1

var2=1234

echo "The value of var2 is $var2"

echo $HOME

echo $PATH

echo $PWD

#! /bin/sh

num=0

while [ $num -le 10 ]

do

num=`expr $num + 1`

if [ $num -eq 5 ]

then

continue

fi

square=`expr $num \* $num`

echo $square

done

#!/bin/bash

# Gnu bash versions 2.x

# The Party Program--Invitations to friends from the

# "guest" file

guestfile=./guests # ~/shell/guests

if [[ ! -e "$guestfile" ]]

then

printf "${guestfile##*/} non-existent"

exit 1

fi

export PLACE="Sarotini's"

(( Time=$(date +%H) + 1 ))

set cheese crackers shrimp drinks "hot dogs" sandwiches

for person in $(cat $guestfile)

do

if [[ $person = root ]]

then

continue

else

# Start of here document

mail -v -s "Party" $person

Hi ${person}! Please join me at $PLACE for a party!

Meet me at $Time o'clock.

I'll bring the ice cream. Would you please bring $1

and anything else you would like to eat? Let me know

if you can't make it.

Hope to see you soon.

Your pal,

ellie@$(hostname)

FINIS

shift

if (( $# == 0 ))

then

set cheese crackers shrimp drinks "hot dogs" sandwiches fi

fi

done

printf "Bye..."

#!/bin/sh

# Standard AT&T Bourne Shell

# The Party Program--Invitations to friends from the

# "guest" file

guestfile=./guests # /home/ellie/shell/guests

if [ ! -f "$guestfile" ]

then

echo "慴asename $guestfile?non-existent"

exit 1

fi

PLACE="Sarotini's"

export PLACE

Time=`date +%H`

Time=`expr $Time + 1`

set cheese crackers shrimp drinks "hot dogs" sandwiches

for person in $(cat $guestfile)

do

if [ $person = root ]]

then

continue

else

# Start of here document

相关文档
最新文档