Chinaunix
标题:
列表格式
[打印本页]
作者:
zhuifeng_wsd
时间:
2015-05-29 18:04
标题:
列表格式
想做成如下的列表:
PKG_LST="\
40PIN \
80PIN \
100PIN \
"
这样我可以根据需要加注释,比如
PKG_LST="\
40PIN \
#80PIN \
#100PIN \
"
本意是只剩下40PIN,可现在却还是3个,第二三个的名字也变成#80PIN,#100PIN.
请大神指教有什么好方法吗?
作者:
stupid_lee
时间:
2015-05-29 18:09
没看懂你说什么
作者:
zhuifeng_wsd
时间:
2015-05-29 18:10
就是让这个列表的有效值个数可选。比如全打开有3个元素,我想注视掉两个,只剩下一个元素。
作者:
jason680
时间:
2015-05-29 18:44
回复
1#
zhuifeng_wsd
How about this way ...
PKG1=40PIN
#
PKG2=80PIN
#
PKG3=100PIN
PKG_LST="$PKG1 $PKG2 $PKG3"
作者:
zhuifeng_wsd
时间:
2015-05-29 18:47
回复
4#
jason680
非常感谢,这个方法很不错
作者:
reyleon
时间:
2015-05-29 19:36
#!/bin/bash
format() {
echo "$(awk 'NF && !/^[ \t]*#/' <<< "$@")"
}
PKG_LST1="
40PIN
80PIN
100PIN
"
PKG_LST2="
40PIN
#80PIN
#100PIN
"
## 注意加上双引号(养成好习惯)
echo "PKG_LST1 values:"
format "$PKG_LST1"
echo
echo "PKG_LST2 values:"
format "$PKG_LST2"
复制代码
作者:
jason680
时间:
2015-05-29 20:08
回复
5#
zhuifeng_wsd
the other way
PKG_LST="${PKG_LST}40PIN "
#PKG_LST="${PKG_LST}80PIN "
PKG_LST="${PKG_LST}100PIN "
作者:
liuyu85
时间:
2015-05-30 17:50
保留40PIN
awk -va="40" '/PIN/&&$0!~"^"a"PIN"{$0="#"$0}1'
复制代码
保留80PIN
awk -va="80" '/PIN/&&$0!~"^"a"PIN"{$0="#"$0}1'
复制代码
改下相应的数字就行
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2