實(shí)驗(yàn)三Linux下的shell編程_第1頁(yè)
實(shí)驗(yàn)三Linux下的shell編程_第2頁(yè)
實(shí)驗(yàn)三Linux下的shell編程_第3頁(yè)
實(shí)驗(yàn)三Linux下的shell編程_第4頁(yè)
實(shí)驗(yàn)三Linux下的shell編程_第5頁(yè)
已閱讀5頁(yè),還剩4頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、山西大學(xué)計(jì)算機(jī)與信息技術(shù)學(xué)院實(shí) 驗(yàn) 報(bào) 告姓名學(xué)乃專(zhuān)業(yè)班級(jí)計(jì)算機(jī)科學(xué)與技術(shù)課程名稱(chēng)操作系統(tǒng)實(shí)驗(yàn)h期2013. 11. 23成績(jī)指導(dǎo)教師批改日期實(shí)驗(yàn)名稱(chēng)實(shí)驗(yàn)三linux下的shell編程一、實(shí)驗(yàn)冃的(1) 了解shell在操作系統(tǒng)中的作用。(2) 理解i/o重定向和管道。(3) 學(xué)會(huì)編寫(xiě)簡(jiǎn)單的shell腳本程序。(4) 學(xué)會(huì)運(yùn)行shell命令文件。二、實(shí)驗(yàn)內(nèi)容實(shí)驗(yàn)1 shell腳本測(cè)試實(shí)驗(yàn)2 shell腳本設(shè)計(jì)三、實(shí)驗(yàn)步驟與結(jié)果(1) 進(jìn)一步體會(huì)shell編程的目的主要是為了管理linux,只有將shell編程和linux系統(tǒng)管理 結(jié)合起來(lái),才能真正掌握shell編程的精髓。(2) 描述各腳本的

2、功能和輸岀結(jié)構(gòu),寫(xiě)入實(shí)驗(yàn)報(bào)告。 輸出:功能:實(shí)現(xiàn)棊木輸入輸出功能,以下程序?qū)崿F(xiàn)了輸入一個(gè)數(shù),然后依次循環(huán)輸出比此數(shù)小 的數(shù)。(如,輸入2,輸出:1 12)使用命令介紹:echo:命令格式:echo arg;功能:在屏幕上打印出arg指定的字符串。bash:調(diào)用bash的形式是:bash-選擇項(xiàng)shell程序文件名;功能:shell程序的調(diào)試主要是利用bash命令解釋程序的選擇項(xiàng) 常用的選擇項(xiàng):e:如果一個(gè)命令失敗,就立即退出。n:讀入命令但是不執(zhí)行它們。u:置換時(shí)把未設(shè)置的變最看做出錯(cuò)。v:當(dāng)讀入shell輸入行時(shí)把它們都顯示出來(lái)。x :執(zhí)行命令時(shí)把命令和它們的參數(shù)顯示出來(lái)。運(yùn)行結(jié)果:1121

3、23 功能:輸出九九乘法表 輸出結(jié)果:1 x 1=11 x2=22x2=41 x3=32x3=63 x 3=91 x4=42x4=83x4=124x4=161 x5=52x5=103x5=154 x 5=205 x 5=251 x6=62x6=123x6=184 x 6=245 x 6=306 x 6=361 x7=72x7=143 x 7=214 x 7=285 x 7=356 x 7=42 7 x 7=491 x8=82x8=163 x 8=244 x 8=325 x 8=406 x 8=48 7 x 8=568 x 8=641 x9=92x9=183 x 9=274 x 9=365 x

4、9=456 x 9=54 7 x 9=638 x 9=72 9x9=81 計(jì)算器功能:實(shí)現(xiàn)了一個(gè)簡(jiǎn)單的計(jì)算器功能,可以實(shí)現(xiàn)加、減、乘、除,并且輸出計(jì)算結(jié)果。 使用命令介紹:read:命令格式:read變量名。功能:從標(biāo)準(zhǔn)輸入設(shè)備讀入一行,分解成若干行字,賦值給shell程序內(nèi)部定義的 變量。運(yùn)行結(jié)果:> done+*/qplease type your word :(e.g.1 + 2)1 +21+2 = 3+/qplease type your word :(e.g.1 + 2)1 *21*2 = 2+/qplease type your word :(e.g.1 + 2)m輸出當(dāng)前r

5、i錄下所有文件,并輸出文件總數(shù)和冃錄總數(shù)。功能:實(shí)現(xiàn)了統(tǒng)計(jì)當(dāng)刖文件下的文件和冃錄的總數(shù)。并且,輸出統(tǒng)計(jì)結(jié)果。使用命令介紹:expr 命令格式:expr argument operator argument功能:用于整數(shù)數(shù)值計(jì)算,但也可以用于字符串操作。輸出結(jié)果:rootlocalhost # is -al總計(jì)336drwxr-x19 root root4096 12-07 10:52 .drwxr-xr-x 24 root root4096 12-07 08:38 .-rw1 root root1464 2011 -11 -04 anaconda-ks.cfg-rw1 root root444

6、 12-07 10:31 .bash_history-rw-r-r-1 root root24 2006-07-13 .bash logout-rw-r-r-1 root root191 2006-07-13 .bash_profile-rw-r-r-1 root root176 2006-07-13 .bashrcdrwx2 root root4096 2011-11-04 .chewingdrwx3 root root4096 2011-11-04 .config-rw-r-r-1 root root100 2006-07-13 .cshrcdrwxr-xr-x2 root root409

7、6 12-07 10:31 desktop-rw1 root root26 2011-11-04 .dmrcdrwxr-x一2 root root4096 2011-11-04 .eggcupsdrwxr-xr-x3 root root4096 12-07 10:32 .emacs.d-rw1 root root162011-11-04 .esd_authdrwx4 root root4096 12-07 08:41 .gconfdrwx2 root root4096 12-07 10:32 .gconfddrwxr-xr-x3 root root4096 2011-11-04 .gnomed

8、rwx6 root root4096 2011-11-04 ,gnome2drwx2 root root4096 2011-11-04 .gnome2_privatedrwxr-xr-x2 root root4096 2011-11-04 .gstreamer-0.10-rw-r-r-1 root root81 2011-11-04 .gtkrc-1.2-gnome2-rw1 root root189 12-07 08:41 .iceauthority-rw-r-r-1 root root 38706 2011-11 -04 install.log-rw-r-r-1 root root4366

9、 2011-11-04 install.log.syslogdrwx3 root root4096 2011-11-04 .metacitydrwxr-xr-x3 root root4096 2011-11-04 .nautilus-rw-r-r-1 root root1157 12-07 10:52 .recently-used.xbeldrwxr-xr-x3 root root4096 2011-11-04 .redhatdrwx 4 root root 4096 2011 -11-04 .scim -rw-r-r- 1 root root 65 12-07 10:37 shuru-rw

10、1 root root 12288 12-07 10:30 .swp-rw-r-r- 1 root root129 2006-07-13 .tcshrcdrwx3 root root4096 2011-11-04 .thumbnailsdrwx2 root root 4096 2011-11-04 .trash-rw-r-r-1 root root1761 12-07 08:42 .xsession-errorsrootlocalhost # echo ”the number of dirctary is $dirnumhthe number of dirctary is 19rootloca

11、lhost # echo ”the number of file is $filenumhthe number of file is 36 菜單功能:實(shí)現(xiàn)了列舉菜單目錄,改變目錄,編輯文件夾,刪除文件夾,和退出程序的功能。 使用命令介紹:開(kāi)關(guān)語(yǔ)句case條件命令格式:case字符串in模式字符串1)若干個(gè)命令行1 模式字符串2)若干個(gè)命令行2其它命令行esac運(yùn)行結(jié)果:> donelist directoryichange directorycedit fileeremove filerexit menuqan aconda-ks.cfg desktop in stallog insta

12、llo g.syslog list directoryichange directorycedit fileeremove filerexit menuqcenter target directoryebash: cd: e:沒(méi)有那個(gè)文件或目錄 list directoryichange directory.cedit fileeremove filerexit menuqq goodbye 功能:將所輸入的參數(shù)循環(huán)輸出輸出結(jié)果:rootlocalhost # bash shuru a b c d e fa b c d e fb c d e fc d e fd e fe ff 電話本:功能:實(shí)

13、現(xiàn)簡(jiǎn)單的電話本功能,即添加,查詢,刪除,編輯電話,最終還設(shè)置了退出功 能。運(yùn)行結(jié)果:> doneif you want to add a user plese typeaif you want to del a user plese typedif you want to watch all users please typeif you want to bianji users please type.eif you want to exit please typeqaplease type your name :123please type your number:182341225

14、08if you want to add a user plese typeaif you want to del a user plese typedif you want to watch all users please typeif you want to bianji users please type.eif you want to exit please typeqi123f you want to add a user plese typeaif you want to del a user plese typedif you want to watc

15、h all users please typeif you want to bianji users please type.eif you want to exit please typeq 判斷當(dāng)前用戶的類(lèi)型。功能:顯示了當(dāng)前使用的虛擬機(jī)的用戶名稱(chēng)。運(yùn)行結(jié)果:rootlocalhost # #!/bin/bashrootlocalhost # case $uid in> 0) echo this is root;> 0-90-9) echo this is system;> 1 -40-90-9) echo this is service;> *) echo thi

16、s is public;> esacthis is root 用一個(gè)文件記錄系統(tǒng)屮所有rpm包名,如果文件不存在則創(chuàng)建,如果存在則顯示文件內(nèi)容。功能:創(chuàng)建一個(gè)文件,把系統(tǒng)屮的所有某類(lèi)包名,用此文件記錄。運(yùn)行結(jié)果:rootlocalhost # #!/bin/bashrootlocalhost # a=/root/filerootlocalhost # if -f $a > then> cat $a> else> rpm -qa > $a>fi產(chǎn)生一個(gè)file文件:file文件屮記錄rpm包名: 功能:創(chuàng)建一個(gè)電話木,可新建聯(lián)系人,刪除聯(lián)系人,査看聯(lián)系人

17、列表以及編輯聯(lián)系人。 輸出結(jié)果:rootlocalhost # bash f10xinjian1denglu2exit-31user name123 passwd 123456xinjian1denglu-2exit32 user name123passwd123456success(3)完成實(shí)驗(yàn)二,將運(yùn)行結(jié)果寫(xiě)入實(shí)驗(yàn)報(bào)告。題目:設(shè)計(jì)一個(gè)shell腳本,完成下述功能:創(chuàng)建四個(gè)文件testl, test2, test3, test4, 實(shí)現(xiàn)自動(dòng)創(chuàng)建 dir1, dir2, dir3. dir4 四個(gè)目錄,并將 testl, test2, test3, test4 四個(gè)文件分別復(fù)制到dir1, dir2, dir3. dir4相應(yīng)目錄下。程序如下:rootlocalhost # #!/bin/bashrootlocalhost # for a in 1 2 3 4;> do> touch test$a> mkd

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論