在bash,我如何计算一个变量的行数? [英] In bash, how do I count the number of lines in a variable?
本文介绍了在bash,我如何计算一个变量的行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经有存储在它的字符串中的无功,需要检查是否有行吧:
i have a var which has a string stored in it and need to check if it has lines in it:
var=`ls "$sdir" | grep "$input"`
伪code:
while [ ! $var's number of lines -eq 1 ]
do something
这就是我如何检查,回声是$ var理念|厕所-l
不起作用,它总是说,即使1有3
thats my idea on how to check, echo $var | wc -l
doesnt work, it always says 1 even though it has 3
回声-e
不起作用
推荐答案
行情事情。
echo "$var" | wc -l
这篇关于在bash,我如何计算一个变量的行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文