日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux shell程序设计实验报告,linux的shell脚本实验报告

發布時間:2023/12/15 linux 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux shell程序设计实验报告,linux的shell脚本实验报告 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

《linux的shell腳本實驗報告》由會員分享,可在線閱讀,更多相關《linux的shell腳本實驗報告(7頁珍藏版)》請在人人文庫網上搜索。

1、第二次實驗內容一、實驗名稱:Linux下shell編程二、實驗類型:設計三、實驗目的:1 熟悉Linux的shell幾種變量使用2 熟練掌握Linux的shell編程幾種結構3 熟練掌握Linux下shell腳本的編寫四、實驗準備參考教材,課件第7章內容及筆記。要求實驗內容全部寫到實驗報告上(B5紙)。五、實驗內容1. 練習使用shell四種變量,參考課件例題。用戶自定義變量,環境變量,位置變量,特殊變量這四種變量類型的使用,書中有例題。2. 調試課件所有shell腳本的例題。3. 編寫如下腳本:l 編寫腳本if1,測試其功能。 echo -n word 1: read word1echo -。

2、n word 2: read word2if test $word1 = $word2thenecho Matchfiecho End of program.l 編寫腳本chkargs,測試其功能if test $# -eq 0thenecho You must supply at least one argument.exit 1fiecho Program running.l 編寫腳本if2,測試其功能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 編寫腳本if3,測試其功能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 編寫smartzip 腳本,測試其功能#!/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 編寫腳本dirfiles,測試其功能。for i in *doif -d $i thenecho $ifidonel 編寫腳本until1,測試其功能。用while改寫之。secretname=jennyname=nonameecho Try to guess the secret name!echountil $name = $secretname /while改寫位 while “$name” != “$secretname” ,其他地方不變doecho -n Your guess: read namedone。

6、echo Very good.l 編寫腳本brk,測試其功能。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 編寫腳本command_menu,測試其功能。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 編寫腳本demo_shift,測試其功能。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 編寫shell腳本sum1,求命令行上整數和。即:$./sum1 5 12 4 6,給出和的結果。sum=0for i in $*do let sum=sum+idoneecho “和是:$sum”l 編寫腳本filetest,判斷當前目錄下所有文件類型,如果是普通文件,顯示文件內容;如果是目錄文件,顯示目錄列表;如果是大小為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 編寫shell腳本user,判斷當前登錄用戶是否為“學號命名”的用戶,是,提示:hello “學號用戶”,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 編寫shell腳本menu,使用shell編寫一個菜單,分別實現列出以下內容:(1)顯示目錄內容、(2)切換目錄、(3)創建文件、(4)編輯文件、(5)刪除文件的l 功能。在此例中將用到循環語句、分支語句和輸入輸出語句。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 編寫腳本,實現一個簡單計算器。+ addition- subtractionx multiplication/ division腳本執行形式:$ ./cal.sh 21 / 3Let l=$1 /最簡單的一種形式,而且還特別高效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六、實驗總結。

總結

以上是生活随笔為你收集整理的linux shell程序设计实验报告,linux的shell脚本实验报告的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。