Pages

2011年2月13日 星期日

我的Shell Script學習心得(一):檔案的操作

以下是我學習Shell Script過程中,整理下來的心得。

我常用的Linux指令符號:

1. "|"符號用法:
(第一個指令)|(第二個指令):代表第一個指令結果導到第二個指令的input。

2. ">"用法:
(1)>(2):代表(1)存到(2)。

3. ">>"用法:
(1)>>(2):代表(1)append到(2)。
---------------------------------------------------------------------------------------------------------------------------------
以下是我寫的一個能將檔案更新一行資料的程式:

#!bin/bash
#test1.sh
#This code was written by Uncle on 2011/02/14
#This code can update a new line into file named "test_file" in current directory.

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH


echo $1>>./test_file
echo "Update successful."

#end
---------------------------------------------------------------------------------------------------------------
以下是執行方式。
在終端機輸入指令:
$ sh test1.sh Uncle
執行結果:
Update successful.

在終端機輸入指令:
$ cat test_file
執行結果:
.....file舊的資料顯示在此...
Uncle --->多了一筆資料更新叫作"Uncle"。
---------------------------------------------------------------------------------------------------------------

沒有留言:

張貼留言