LinuxShell脚本编程实例
《LinuxShell脚本编程实例》由会员分享,可在线阅读,更多相关《LinuxShell脚本编程实例(5页珍藏版)》请在装配图网上搜索。
1、#! /bin/sh echo Current command is $0echo 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/bashtimes=0until $times = 3 ;doecho I love linux.sleep 2times=expr $times + 1done#!/bin/bash# menu shell scrip
2、t. samli 2004.4.19untilecho List Directory1echo Change Directory2echo Edit File3echo Remove File4echo Exit Menu5read choicetest $choice = 5docase $choice in1) ls;2) echo enter target directory: read dircd $dir;3) echo enter file name:read filevi $file;4) echo enter file name:read filerm $file5) echo
3、 Goodbye*) echo illegal option, please input again. esacdone#! /bin/sh var1=abcd efg echo $var1 var2=1234echo The value of var2 is $var2”echo $HOME echo $PATH echo $PWD#! /bin/shnum=0while $num -le 10 donum=expr $num + 1 if $num -eq 5 thencontinue fisquare=expr $num * $numecho $squaredone#!/bin/bash
4、# Gnu bash versions 2.x# The Party Program一Invitations to friends from the# guest file guestfile=./guests # /shell/guests if ! -e $guestfilethenprintf $guestfile#*/ non-existent exit 1fiexport PLACE=Sarotinis”(Time=$(date +%H) + 1 )set cheese crackers shrimp drinks hot dogs sandwiches for person in
5、$(cat $guestfile)doif $person = root thencontinueelse# Start of here documentmail -v -s Party $personHi $person! Please join me at $PLACE for a party!Meet me at $Time oclock.Ill bring the ice cream. Would you please bring $1 and anything else you would like to eat? Let me know if you cant make it.Ho
6、pe to see you soon.Your pal, ellie$(hostname)FINISshiftif ( $# = 0 )thenset cheese crackers shrimp drinks hot dogs sandwiches fifidoneprintf Bye.#!/bin/sh# Standard AT&T Bourne Shell# The Party Program一Invitations to friends from the# guest fileguestfile=./guests # /home/ellie/shell/guests if ! -f $
7、guestfile thenecho 熠 asename $guestfile?non-existent”exit 1fiPLACE=Sarotinisexport PLACETime=date +%HTime=expr $Time + 1set cheese crackers shrimp drinks hot dogs sandwiches for person in $(cat $guestfile) doif $person = root thencontinueelse# Start of here document mail -v -s Party $personHi $perso
8、n! Please join me at $PLACE for a party!Meet me at $Time oclock.Ill bring the ice cream. Would you please bring $1 and anything else you would like to eat? Let me know if you cantmake it.Hope to see you soon.Your pal,elliehostnameFINIS shift if $# -eq 0 thenset cheese crackers shrimp drinks hot dogs
9、 sandwiches fifidoneecho Bye.#!/bin/sh# Scriptname: args# Script to test command line arguments echo The name of this script is $0.echo The arguments are $*.echo The first argument is $1.echo The second argument is $2.echo The number of arguments is $#. oldargs=$*set Jake Nicky Scott# reset the posi
10、tional parametersecho All the positional parameters are $*.echo The number of postional parameters is $#.echo GoodVbye for now, $1 set $(date)# reset the positional parametersecho The date is $2 $3, $6.echo The value of $oldargs is $oldargs.set $oldargs echo $1 $2 $3# Name: bigfiles# Purpose: Use th
11、e find command to find any files in the root# partition that have not been modified within the past n (any# number within 30 days) days and are larger than 20 blocks# (512 byte blocks)$# -ne 2 if ( $# != 2 )# orthenecho Usage: $0 mdays size 1&2exit 1fiif ( $10 | $1 30 ) # or $1 -lt 0 -o $1 -gt 30 th
12、enecho mdays is out of rangeexit 2fiif ( $2# or $2 -le 20 thenecho size is out of rangeexit 3fifind / -xdev -mtime $1 -size +$2#!/bin/bash# Scriptname: checker# Script to demonstrate the use of special variable# modifiers and argumentsname=$1:?”requires an argument echo Hello $name #!/bin/bash# This
13、 is the first Bash shell program of the day.# Scriptname: greetings# Written by: Barbara Bashfulecho Hello $LOGNAME, its nice talking to you.echo Your present working directory is pwd.echo You are working on a machine called uname -n. echo Here is a list of your files.ls # list files in the present
14、working directory echo Bye for now $LOGNAME. The time is date +%T! #!/bin/bash# Scriptname: greetings2echo This script is called $0.echo $0 $1 and $2echo The number of positional parameters is $# #!/bin/bash# Scriptname: idcheck# purpose:check user id to see if user is root.# Only root has a uid of 0.# Format for id output:uid=9496(ellie) gid=40 groups=40# roots uid=0id=id | gawk -F=( ,print $2、# get user idecho your user id is: $idif ( id = 0 )# or $id -eq 0 thenecho you are superuser.elseecho you are not superuser.fi
- 温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。