私は配列を分割する必要があります。私はbashの配列の区切り文字を掛けることができます
systemHosts=(here the list on hosts which is around 700 positions)
openSSHlineLimit=1024
systemHostsLength=${#systemHosts[@]}
systemHostsByteLength=$(echo ${systemHosts[@]} | wc -c)
let divideBy=$systemHostsByteLength/$openSSHlineLimit
let modu=$systemHostsByteLength%$openSSHlineLimit
if [[ $divideBy == 0 ]] && [[ $modu != 0 ]]; then
echo "
host ${systemHosts[@]}
user system
" #> ~/.ssh/config
elif [[ $divideBy == 1 ]] && [[ $modu > 0 ]]; then
let getBreak=$systemHostsLength/2
echo "
host ${systemHosts[@]::$getBreak}
user system
" # > ~/.ssh/config
echo "
host ${systemHosts[@]:$getBreak}
user system
" # >> ~/.ssh/config
elif [[ $divideBy == 2 ]] && [[ $modu > 0 ]]; then
let getBreak=$systemHostsLength/3
echo "
host ${systemHosts[@]::$getBreak}
user system
" # > ~/.ssh/config
echo "
host ${systemHosts[@]:$getBreak:$getBreak}
user system
" # > ~/.ssh/config
echo "
host ${systemHosts[@]:$getBreak*2}
user system
" # > ~/.ssh/config
elif [[ $divideBy == 3 ]] && [[ $modu > 0 ]]; then
echo "
host ${systemHosts[@]::$getBreak}
user system
" # > ~/.ssh/config
echo "
host ${systemHosts[@]:($getBreak:$getBreak}
user system
" # > ~/.ssh/config
echo "
host ${systemHosts[@]:$getBreak*3:$getBreak}
user system
" # > ~/.ssh/config
echo "
host ${systemHosts[@]:$getBreak*4}
user system
" # > ~/.ssh/config
elif [[ $divideBy == 4 ]] && [[ $modu > 0 ]]; then
echo "
host ${systemHosts[@]::$getBreak}
user system
" # > ~/.ssh/config
echo "
host ${systemHosts[@]:$getBreak*2:$getBreak}
user system
" # > ~/.ssh/config
echo "
host ${systemHosts[@]:$getBreak*3:$getBreak}
user system
" # > ~/.ssh/config
echo "
host ${systemHosts[@]:$getBreak*4:$getBreak}
user system
" # > ~/.ssh/config
echo "
host ${systemHosts[@]:$getBreak*5}
user system
" # > ~/.ssh/config
fi
それらの部品::私はこのコードを作った
${systemHosts[@]:$getBreak*2:$getBreak}
${systemHosts[@]:$getBreak*3:$getBreak}
${systemHosts[@]:$getBreak*4:$getBreak}
は本当に しかし、この
${systemHosts[@]:$getBreak*2}
作品完璧に
を動作しません。私はそれが表現することを... [@]:$ var * n:$ varはありません許可されるか、私は何か間違っている?
。 。 。 。 。 。 。 。 。 。更新/解決/ 。 。 。 。 。 。 。 。 。 。
こんにちは。私はこのquestinためanswaringをブロックされて私はここに書く:< 私は追加するのを忘れているため、スクリプトが動作しませんでした:
let getBreak=$systemHostsLength/<divider>
各ELIFの初めに:すべてのために多くを悩まと感謝のために/ は申し訳ありません; answares)
私は実際にはすでに問題を解決しました。あなたの方法ははるかにクリーンで良い。ありがとうございます – eswues
http://mywiki.wooledge.org/XyProblem ... upvotingに対してポリシーを持っているかどうか聞いてもよろしいですか? – gboffi
hehehe。リンクありがとう:P – eswues