Re: script執行檔案 - Linux

Table of Contents

※ 引述《"[email protected]" <[email protected]>, 看板: Linux》之銘言:
這是 passing command line arguments 的問題,
那就是,如何在 shell script 裡讀取指令行上的其它參數。
簡單的答案是:

#!/bin/sh
cat "$1"

$1 就會被 shebang "#!" 後所註明的 shell 取代為指令行上的第一個參數。
最好括上雙引號,以避免檔名裡含有空白(spaces)的問題。

如果希望一次給好幾個檔名:

#!/bin/sh
cat "$@"


--
此為local存檔;
因為bs2可以看得到文章的內容,所以我就幫忙轉貼原本的內容

--

All Comments