开发者

shell script + constant spaces between the IP to the aliases name

from my ksh script

.

echo $IP1  $ALIAS1 >> /etc/hosts
echo $IP2  $ALAIS2 >> /etc/hosts
echo $IP3  $ALIAS3 >> /etc/hosts

I get the hosts fi开发者_JS百科le as the following

10.10.10.10 node1_star
10.10.10.100    node_from_some_where
10.10.1.1              Node_HP_MACHINE

what the simple way to create the following hosts file view in order to get constant spaces between the IP to the aliases name as the follwoing:

(it could be by printf or by echo manipulation)

10.10.10.10        node1_star
10.10.10.100       node_from_some_where
10.10.1.1          Node_HP_MACHINE


printf is a powerful function that can do exactely what you want.

printf "%-20s %s\n" "$IP1" "$ALIAS1" >> /etc/hosts
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜