原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://dgd2010.blog.51cto.com/1539422/1718284
# Linux shell将字符串分割成数组
1 2 |
|
# 判断一个变量是否存在(不是判断是否为空)
1 |
|
# 判断一个变量是否为空
1 2 |
|
#系统变量用后还原
# 关于IFS的定义:IFS,Internal Field Separator
# An Internal Field Separator (IFS) is an environment variable that stores delimiting characters.
# It is the default delimiter string used by a running shell environment.
# "$*" expands as "$1c$2c$3", where c is the first character of IFS
# When the expansion occurs within double quotes, it expands to a single word with the value of each parameter separated by the first character of the IFS special variable.
# That is, "$*" is equivalent to "$1c$2c...", where c is the first char‐acter of the value of the IFS variable.
# If IFS is unset, the parameters are separated by spaces. If IFS is null, the parameters are joined without intervening separators.
1 2 3 4 5 6 7 |
|
# 使用facter获取一组key-value
# facter的输出有换行符,必须把换行符替换成空格
# 将换行符替换成空格可以使用awk或sed
# awk -v RS="" '{gsub("\n"," ");print}'
# echo -e "2 \n1" | sed ':a;N;$!ba;s/\n/ /g'
1 2 3 |
|
# 输出key
1 2 3 |
|
# 输出value
1 2 3 |
|
# 输出key-value
1 2 3 4 |
|
--end--
本文出自 “通信,我的最爱” 博客,请务必保留此出处http://dgd2010.blog.51cto.com/1539422/1718284