Re: script執行檔案 - Linux

By Elvira
at 2011-12-09T18:14
at 2011-12-09T18:14
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可以看得到文章的內容,所以我就幫忙轉貼原本的內容
--
這是 passing command line arguments 的問題,
那就是,如何在 shell script 裡讀取指令行上的其它參數。
簡單的答案是:
#!/bin/sh
cat "$1"
$1 就會被 shebang "#!" 後所註明的 shell 取代為指令行上的第一個參數。
最好括上雙引號,以避免檔名裡含有空白(spaces)的問題。
如果希望一次給好幾個檔名:
#!/bin/sh
cat "$@"
--
此為local存檔;
因為bs2可以看得到文章的內容,所以我就幫忙轉貼原本的內容
--
Tags:
Linux
All Comments
Related Posts
Re: AWK 傳結果到SHELL指定變數

By Quanna
at 2011-12-09T18:12
at 2011-12-09T18:12
AWK 傳結果到SHELL指定變數

By Noah
at 2011-12-09T13:15
at 2011-12-09T13:15
關於抹除資料

By William
at 2011-12-09T12:54
at 2011-12-09T12:54
linux mint 筆電

By Edith
at 2011-12-09T11:45
at 2011-12-09T11:45
gnome3 拖曳放大 功能失效

By Linda
at 2011-12-09T09:49
at 2011-12-09T09:49