Re: [問題] shell script 檔案移動
※ 引述《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……以此類推
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.116.131.235
推
07/25 17:22, , 1F
07/25 17:22, 1F
討論串 (同標題文章)