#!/bin/bash
#------------------------------------
#Time:2010/05/03 22:41
#Author:Johnny
#Comment:建立一個屬於自己格式的Shell Script
#------------------------------------

# 檢查參數是否足夠
[ "$#" -lt 1 ] && echo "ERROR: Missing arguments (less than 1)." \
        && exit 0

# 檢查檔案是否存在,不存在就建立
if [ "$(cat $1)" == '' ]; then
echo "File Created."
else
echo "ERROR: File exist." && exit 0
fi

# 建立其檔案內容(註:中間的註解也會被寫入,中間可以修改作者的名字)
cat > $1 <<end
#!/bin/bash
#------------------------------------
#Time:$(date +%Y)/$(date +%m)/$(date +%d) $(date +%H):$(date +%M)
#Author:Johnny
#Comment:
#------------------------------------
end
# 該屬性更改為可執行的檔案
chmod +x $1

我在這裡解釋一下這要怎麼用

將其存成mksh,可以直接放在/bin下

就可以直接打

$ mksh test.sh

就會有一個自己格式的shell script了

$ cat test.sh

#!/bin/bash
#------------------------------------
#File:test.sh
#Time:2010/05/03 23:35
#Author:Johnny
#Comment:
#------------------------------------


arrow
arrow
    全站熱搜

    Johnny 鋼鍊 發表在 痞客邦 留言(0) 人氣()