Chinaunix
标题:
substr截取字符串不成功.
[打印本页]
作者:
juklow
时间:
2014-08-25 12:57
标题:
substr截取字符串不成功.
代码:
echo $_str | awk '{print substr($0, $_chop)}'
复制代码
以上,_str和_chop我都可以设置好值.
比如
_str="Hello,J"
_chop=3
但是上面的代码都没有帮我截取.返回的是 _str整个字符串.何解?
我直接用一个数字,如 3 取代
echo $_str | awk '{print substr($0, $_chop)}'
复制代码
中的 _chop 为
echo $_str | awk '{print substr($0, 3)}'
复制代码
又正常.
作者:
yestreenstars
时间:
2014-08-25 13:53
echo $_str | awk -v chop=$_chop '{print substr($0,chop)}'
复制代码
echo $_str | awk '{print substr($0,'$_chop')}'
复制代码
echo ${_str:$_chop-1}
复制代码
作者:
juklow
时间:
2014-08-26 21:51
回复
2#
yestreenstars
能解决...谢了...哥们.
作者:
action08
时间:
2014-08-27 09:45
这个问题,shell板块的人回答更专业
作者:
juklow
时间:
2014-08-28 15:41
回复
4#
action08
ok,初来不久...谢啦..
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2