迴圈內變數中的變數問題? - Linux
By Adele
at 2015-05-18T19:10
at 2015-05-18T19:10
Table of Contents
首先,小弟我的問題標題實在不知道要怎麼下,傷眼抱歉
如果有十多台電腦想丟同一個檔案上去,電腦的IP不是連續的
小弟我想寫一個腳本先設定變數為各台電腦的IP,變數為連續的
然後用迴圈去帶出個別電腦的IP位址,實在是不知道要如何寫這個變數,
爬文#1Ighf6r6 裡面的變數寫法也都失敗,顯示Bad substitution,
特此來請教各位前輩,感謝。
系統:HP-UX 沒有bash,只能使用sh,故採用while寫法。
程式碼如下:
#!/bin/sh
#set
i=0
ip1=11.11.111.111
ip2=22.22.222.222
ip3=33.33.333.333
ip4=44.44.444.444
ip5=55.55.555.555
#loop
while [ $i -le 4 ]; do
i=$(($i + 1))
echo "$i"
varname=ip$i
echo ${!varname}
done
--
如果有十多台電腦想丟同一個檔案上去,電腦的IP不是連續的
小弟我想寫一個腳本先設定變數為各台電腦的IP,變數為連續的
然後用迴圈去帶出個別電腦的IP位址,實在是不知道要如何寫這個變數,
爬文#1Ighf6r6 裡面的變數寫法也都失敗,顯示Bad substitution,
特此來請教各位前輩,感謝。
系統:HP-UX 沒有bash,只能使用sh,故採用while寫法。
程式碼如下:
#!/bin/sh
#set
i=0
ip1=11.11.111.111
ip2=22.22.222.222
ip3=33.33.333.333
ip4=44.44.444.444
ip5=55.55.555.555
#loop
while [ $i -le 4 ]; do
i=$(($i + 1))
echo "$i"
varname=ip$i
echo ${!varname}
done
--
Tags:
Linux
All Comments
By Edith
at 2015-05-21T03:02
at 2015-05-21T03:02
By Erin
at 2015-05-22T10:17
at 2015-05-22T10:17
By Carol
at 2015-05-22T13:01
at 2015-05-22T13:01
By Thomas
at 2015-05-25T14:00
at 2015-05-25T14:00
By Jessica
at 2015-05-29T03:21
at 2015-05-29T03:21
By Doris
at 2015-06-02T11:40
at 2015-06-02T11:40
By Ophelia
at 2015-06-04T10:57
at 2015-06-04T10:57
By Aaliyah
at 2015-06-09T10:12
at 2015-06-09T10:12
By Damian
at 2015-06-11T21:17
at 2015-06-11T21:17
By Ivy
at 2015-06-15T21:10
at 2015-06-15T21:10
By Isla
at 2015-06-19T11:45
at 2015-06-19T11:45
By Adele
at 2015-06-24T11:38
at 2015-06-24T11:38
By Sandy
at 2015-06-25T17:52
at 2015-06-25T17:52
By Frederica
at 2015-06-28T23:37
at 2015-06-28T23:37
By Ingrid
at 2015-07-03T16:43
at 2015-07-03T16:43
By Yedda
at 2015-07-08T10:04
at 2015-07-08T10:04
By Olive
at 2015-07-10T05:49
at 2015-07-10T05:49
By Ina
at 2015-07-12T12:11
at 2015-07-12T12:11
By Mary
at 2015-07-15T05:56
at 2015-07-15T05:56
By Hedda
at 2015-07-19T17:12
at 2015-07-19T17:12
By Catherine
at 2015-07-21T21:25
at 2015-07-21T21:25
By Andy
at 2015-07-26T12:24
at 2015-07-26T12:24
By Ula
at 2015-07-28T17:18
at 2015-07-28T17:18
By Ula
at 2015-08-01T05:47
at 2015-08-01T05:47
By Edward Lewis
at 2015-08-05T04:26
at 2015-08-05T04:26
Related Posts
Ubuntu SCTP CMT mode
By Frederica
at 2015-05-18T09:12
at 2015-05-18T09:12
nfs檔案砍不掉
By Callum
at 2015-05-17T19:59
at 2015-05-17T19:59
無線網卡附的driver跟系統抓的不一樣
By Emily
at 2015-05-17T17:43
at 2015-05-17T17:43
如何在script中確定mount有成功
By Iris
at 2015-05-17T17:09
at 2015-05-17T17:09
要如何改lsusb連結的硬體資訊?
By David
at 2015-05-16T02:52
at 2015-05-16T02:52