【发布时间】:2022-10-24 05:37:40
【问题描述】:
我正在使用在 serverA 上运行并连接到服务器以运行文件的 bash 脚本。 结果保存在变量中,然后回显。但是,它不会回显所有数据。
serverA 上的脚本正在运行:
count=$(sshpass -p password ssh -t -q user@serverB cd /home/tom && ./count.sh)
echo "Count: $count"
这回声:341 不是Count: 341
serverB 上的 count.sh 脚本循环遍历一些文件夹并计算文件。
例如。
total=0
count=$(ls -l | wc -l | xargs)
if [ "$count" > 0 ]; then
total=$(( total + count ))
fi
echo "$total"
如何在 serverA 上显示完整的回声?
【问题讨论】:
-
./count.sh未在 serverB 上执行。 serverB 上唯一执行的是 cd 命令。如果你执行'cd /home/tom && ./count.sh',那么它可能会更接近正确。我相信您没有展示实际的 MCV 示例。