原创作品,允许转载,转载时请务必以超链接形式标明文章
原始出处 、作者信息和本声明。否则将追究法律责任。
http://dgd2010.blog.51cto.com/1539422/1718284
1
2
|
result=$(facter |
awk
'/ipaddress/ && !/ipaddress_lo/ {print $1 " " $3}'
)
array=($result)
|
1
|
if
[ -z ${var+x} ];
then
echo
"var is unset"
;
else
echo
"var is set to '$var'"
;
fi
|
1
2
|
if
[
"$var x"
=
" x"
];
then
echo
"var is empty"
;
else
echo
"var is set to '$var'"
;
fi
if
[ -z $var ];
then
echo
"var is empty"
;
else
echo
"var is set to '$var'"
;
fi
|
1
2
3
4
5
6
7
|
oldIFS=
"$IFS"
IFS=
" "
array=($result)
IFS=
"$oldIFS"
for
i
in
${array[@]};
do
echo
$i
done
|
1
2
3
|
result=$(facter |
awk
'/ipaddress/ && !/ipaddress_lo/ {print $1 " " $3}'
|
awk
-
v
RS=
""
'{gsub("\n"," ");print}'
)
array=($result)
array_length=${
#array[@]}
|
1
2
3
|
for
(( i = 0; i < $array_length; i=i+2 ));
do
echo
${array[$i]}
done
|
1
2
3
|
for
(( i = 1; i < $array_length; i=i+2 ));
do
echo
${array[$i]}
done
|
1
2
3
4
|
for
(( i = 0; i < $array_length; i=i+2 ));
do
j=$i+1
echo
"${array[$i]} - ${array[$j]}"
done
|