linux shell程序设计实验报告,linux的shell脚本实验报告
《linux的shell腳本實(shí)驗(yàn)報(bào)告》由會(huì)員分享,可在線閱讀,更多相關(guān)《linux的shell腳本實(shí)驗(yàn)報(bào)告(7頁(yè)珍藏版)》請(qǐng)?jiān)谌巳宋膸?kù)網(wǎng)上搜索。
1、第二次實(shí)驗(yàn)內(nèi)容一、實(shí)驗(yàn)名稱:Linux下shell編程二、實(shí)驗(yàn)類(lèi)型:設(shè)計(jì)三、實(shí)驗(yàn)?zāi)康?#xff1a;1 熟悉Linux的shell幾種變量使用2 熟練掌握Linux的shell編程幾種結(jié)構(gòu)3 熟練掌握Linux下shell腳本的編寫(xiě)四、實(shí)驗(yàn)準(zhǔn)備參考教材,課件第7章內(nèi)容及筆記。要求實(shí)驗(yàn)內(nèi)容全部寫(xiě)到實(shí)驗(yàn)報(bào)告上(B5紙)。五、實(shí)驗(yàn)內(nèi)容1. 練習(xí)使用shell四種變量,參考課件例題。用戶自定義變量,環(huán)境變量,位置變量,特殊變量這四種變量類(lèi)型的使用,書(shū)中有例題。2. 調(diào)試課件所有shell腳本的例題。3. 編寫(xiě)如下腳本:l 編寫(xiě)腳本if1,測(cè)試其功能。 echo -n word 1: read word1echo -。
2、n word 2: read word2if test $word1 = $word2thenecho Matchfiecho End of program.l 編寫(xiě)腳本chkargs,測(cè)試其功能if test $# -eq 0thenecho You must supply at least one argument.exit 1fiecho Program running.l 編寫(xiě)腳本if2,測(cè)試其功能if test $# -eq 0thenecho You must supply at least one argument.exit 1fiif test -f $1thenecho $1。
3、 is a regular file in the working directoryelseecho $1 is NOT a regular file in the working directoryfil 編寫(xiě)腳本if3,測(cè)試其功能echo -n word 1: read word1echo -n word 2: read word2echo -n word 3: read word3if $word1 = $word2 -a $word2 = $word3 thenecho Match: words 1, 2, & 3elif $word1 = $word2 thenecho Match。
4、: words 1 & 2elif $word1 = $word3 thenecho Match: words 1 & 3elif $word2 = $word3 thenecho Match: words 2 & 3elseecho No matchfil 編寫(xiě)smartzip 腳本,測(cè)試其功能#!/bin/bashftype=file $1case $ftype in$1: Zip archive*)unzip $1 ;$1: gzip compressed*)gunzip $1 ;$1: bzip2 compressed*)bunzip2 $1 ;*) echo File $1 can 。
5、not be uncompressed with smartzip;esacl 編寫(xiě)腳本dirfiles,測(cè)試其功能。for i in *doif -d $i thenecho $ifidonel 編寫(xiě)腳本until1,測(cè)試其功能。用while改寫(xiě)之。secretname=jennyname=nonameecho Try to guess the secret name!echountil $name = $secretname /while改寫(xiě)位 while “$name” != “$secretname” ,其他地方不變doecho -n Your guess: read namedone。
6、echo Very good.l 編寫(xiě)腳本brk,測(cè)試其功能。for index in 1 2 3 4 5 6 7 8 9 10doif $index -le 3 ; thenecho continuecontinuefi#echo $index#if $index -ge 8 ; thenecho breakbreakfidonel 編寫(xiě)腳本command_menu,測(cè)試其功能。echo -e n COMMAND MENUnecho a. Current date and timeecho b. Users currently logged inecho c. Name of the wor。
7、king directoryecho -e d. Contents of the working directorynecho -n Enter a, b, c, or d: read answerechocase $answer ina)date;b)who;c)pwd;d)ls;*)echo There is no selection: $answer;esacl 編寫(xiě)腳本demo_shift,測(cè)試其功能。echo arg1= $1 arg2= $2 arg3= $3shiftecho arg1= $1 arg2= $2 arg3= $3shiftecho arg1= $1 arg2= $。
8、2 arg3= $3shiftecho arg1= $1 arg2= $2 arg3= $3shiftl 編寫(xiě)shell腳本sum1,求命令行上整數(shù)和。即:$./sum1 5 12 4 6,給出和的結(jié)果。sum=0for i in $*do let sum=sum+idoneecho “和是:$sum”l 編寫(xiě)腳本filetest,判斷當(dāng)前目錄下所有文件類(lèi)型,如果是普通文件,顯示文件內(nèi)容;如果是目錄文件,顯示目錄列表;如果是大小為0的文件,刪除它;否則,顯示“sorry, The file is not recognized!”for i in *do if -d $i then ls $ie。
9、lif -f $i then if -s $i then cat $ielse rm $ifielseecho n “sorry,the file cant be recognized”fidonel 編寫(xiě)shell腳本user,判斷當(dāng)前登錄用戶是否為“學(xué)號(hào)命名”的用戶,是,提示:hello “學(xué)號(hào)用戶”,welcome!,否,提示“you should login using your username! ”Read nameIf $USER = $name Then echo “hello $USER”else echo “you should login using your usern。
10、ame!”fil 編寫(xiě)shell腳本menu,使用shell編寫(xiě)一個(gè)菜單,分別實(shí)現(xiàn)列出以下內(nèi)容:(1)顯示目錄內(nèi)容、(2)切換目錄、(3)創(chuàng)建文件、(4)編輯文件、(5)刪除文件的l 功能。在此例中將用到循環(huán)語(yǔ)句、分支語(yǔ)句和輸入輸出語(yǔ)句。Echo “a.display the directory”Echo “b.change the directory”Echo “c.create a file”Echo “d.delete the file”Echo “if you input nothing,you will exit”Read itemUntil -z $item Do Case $it。
11、em in a) Echo “input the directory”Read direLs $dire;b) Echo “input the directory you want go into”Read direCd $dire;c) Echo “input the file you want to create”Read fTouch $f;d) Echo “input the file you want to delete”Read fRm $f;EsacEcho “a.display the directory”Echo “b.change the directory”Echo “c。
12、.create a file”Echo “d.delete the file”Echo “if you input nothing,you will exit”Read itemdonel 編寫(xiě)腳本,實(shí)現(xiàn)一個(gè)簡(jiǎn)單計(jì)算器。+ addition- subtractionx multiplication/ division腳本執(zhí)行形式:$ ./cal.sh 21 / 3Let l=$1 /最簡(jiǎn)單的一種形式,而且還特別高效Echo $1;第二種方式:Re=”+ - * /”For var in $reDoIf $var = “*” ThenNum2=$1#*Num1=$1%*ElseNum2=$1#*$varNum1=$1#%$var*FiIf $num1 =$1 Then continueFiCase $var in“+”) let num=num1+num2Break;“-“) let num=num1-num2;Break;“*”)let num=num1*num2Break;“/”)let num=num1/num2Break;EsacDoneEcho $num六、實(shí)驗(yàn)總結(jié)。
總結(jié)
以上是生活随笔為你收集整理的linux shell程序设计实验报告,linux的shell脚本实验报告的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux centos密码忘记,Cen
- 下一篇: linux 将img写入硬盘,如何使用E