Changes between Version 3 and Version 4 of YM_Course_2009/Lab4


Ignore:
Timestamp:
Jul 4, 2009, 9:08:56 AM (15 years ago)
Author:
jazz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • YM_Course_2009/Lab4

    v3 v4  
    11{{{
    22#!html
    3 <div style="text-align: center;"><big style="font-weight: bold;"><big>實作四: SSH 遠端登入指令</big></big></div>
     3<div style="text-align: center;"><big style="font-weight: bold;"><big>實作四: Bash Shell Script 實作練習</big></big></div>
    44}}}
    55[[PageOutline]]
    66
    77◢ <[wiki:YM_Course_2009/Lab3 實作三]> | <[wiki:YM_Course_2009 回課程大綱]> ▲ | <[wiki:YM_Course_2009/Lab5 實作五]> ◣
     8
     9= 1. 重新導向練習 =
     10
     11 * 首先,讓我們來練習 I/O 重新導向表上的指令。
     12 * 使用 > 或 1> 把 ls 指令的 STDOUT 結果導向到 file 與 file2 這兩個檔案,結果是相似的。
     13 * 你可能會注意到 file 裡有出現 file,file2 裡才有出現 file2,代表檔案是先產生,然後才執行 ls 指定的。
     14{{{
     15ubuntu@ubuntu:~$ ls > file
     16ubuntu@ubuntu:~$ cat file
     17file
     18profile
     19temp
     20temp2
     21ubuntu@ubuntu:~$ ls 1> file2
     22ubuntu@ubuntu:~$ cat file2
     23file
     24file2
     25profile
     26temp
     27temp2
     28}}}
     29 * 使用 2> 把 ls 指令的 STDERR 導向到 file3,你會發現 file3 的內容是空的,因為並沒有出現錯誤,而 STDOUT 的結果還是出現在畫面上。
     30{{{
     31ubuntu@ubuntu:~$ ls 2> file3
     32file  file2  file3  profile  temp  temp2
     33ubuntu@ubuntu:~$ cat file3
     34}}}
     35 * 我們刻意下錯指令,例如:ls temp3 來產生 STDERR 輸出。
     36{{{
     37ubuntu@ubuntu:~$ ls temp3 2> file4
     38ubuntu@ubuntu:~$ cat file4
     39ls: cannot access temp3: No such file or directory
     40}}}
     41 * 我們刻意下指令,例如:ls temp temp3 來同時產生 STDOUT 與 STDERR 輸出。
     42{{{
     43ubuntu@ubuntu:~$ ls temp temp3
     44ls: cannot access temp3: No such file or directory
     45temp:
     46ubuntu@ubuntu:~$ ls temp temp3 > file5 2> file6
     47ubuntu@ubuntu:~$ cat file5
     48temp:
     49ubuntu@ubuntu:~$ cat file6
     50ls: cannot access temp3: No such file or directory
     51ubuntu@ubuntu:~$ ls temp temp3 > file7 2>&1
     52ubuntu@ubuntu:~$ cat file7
     53ls: cannot access temp3: No such file or directory
     54temp:
     55ubuntu@ubuntu:~$ ls temp temp3 2> file8 1>&2
     56ubuntu@ubuntu:~$ cat file8
     57ls: cannot access temp3: No such file or directory
     58temp:
     59}}}
     60 * 因為 file8 存在,因此當我們用 >> 來重新導向 cat file 指令的 STDOUT 結果,會附加到 file8 檔案後面。
     61{{{
     62ubuntu@ubuntu:~$ cat file >> file8
     63ubuntu@ubuntu:~$ cat file8
     64ls: cannot access temp3: No such file or directory
     65temp:
     66file
     67profile
     68temp
     69temp2
     70}}}