我有一个多行字符串,我希望它首先被格式化为每行的特定长度,然后再将每行传递给一个函数进行行处理。
例如
description="\
NOTE:
This script should be run on a newly created server.
However it can also be re-run selectively even afterwards, to re configure your settings if they were messed up.
Ready to configure the server for the first time.
"
echo "$description" | fmt -w 80
我现在想遍历上面的输出并将每一行发送到一个函数。
我想象的是这样的(不起作用):
function testme() {
for var in "$@"
do
echo "$var"
done
}
echo "$description" | fmt -w 80 | testme
有任何想法吗?
试试这个方法: