shell script 檔案移動 - Linux

By Agnes
at 2009-07-25T13:29
at 2009-07-25T13:29
Table of Contents
※ 引述《icewm (icewm)》之銘言:
: 檔案/目錄清單: LIST
: FILE1 TARGET1
: FILE2 TARGET2
: ...
: FILEN TARGETN
: script: mov.sh
: #!/bin/sh
: move_file() {
: mv $1 $2
: }
: while [ "$1" != "" ];
: do
: move_file "$1" "$2"
: shift
: shift
: done
-------------------------------------
shift 這個指令還滿好用的
小弟來補充用法:
------------------
#!/bin/bash
while [ "$1" ]
do
echo "$1"
shift
done
--------------------
執行:
1 chmod +x script
2 ./script a b c d e
3 結果:
a
b
c
d
e
--------------------
看到了吧,shift 這個指令的功能就是把參數做左移
一開始是 $1 的參數,每跑完一輪就會shift 一次同時參數
就會變成$2……以此類推
--
: 檔案/目錄清單: LIST
: FILE1 TARGET1
: FILE2 TARGET2
: ...
: FILEN TARGETN
: script: mov.sh
: #!/bin/sh
: move_file() {
: mv $1 $2
: }
: while [ "$1" != "" ];
: do
: move_file "$1" "$2"
: shift
: shift
: done
-------------------------------------
shift 這個指令還滿好用的
小弟來補充用法:
------------------
#!/bin/bash
while [ "$1" ]
do
echo "$1"
shift
done
--------------------
執行:
1 chmod +x script
2 ./script a b c d e
3 結果:
a
b
c
d
e
--------------------
看到了吧,shift 這個指令的功能就是把參數做左移
一開始是 $1 的參數,每跑完一輪就會shift 一次同時參數
就會變成$2……以此類推
--
Tags:
Linux
All Comments

By Yuri
at 2009-07-29T18:49
at 2009-07-29T18:49
Related Posts
shell script 檔案移動

By Elma
at 2009-07-25T07:23
at 2009-07-25T07:23
a big trouble about gcin and scim

By Ida
at 2009-07-25T01:38
at 2009-07-25T01:38
ubuntu下聲音不見的問題

By Olivia
at 2009-07-25T01:21
at 2009-07-25T01:21
proxy server partition切割

By Connor
at 2009-07-25T00:51
at 2009-07-25T00:51
請教bash script問題

By Xanthe
at 2009-07-24T22:25
at 2009-07-24T22:25