shell无限循环find命令

shell无限循环find命令

我正在编写一个 shell 脚本,遇到了这个我无法解决的问题

以下命令应该查找/.

PATHS_SHELL=$(sudo find / -name '*.sh')                                                          

如果我执行该命令而不将其分配给变量,它就可以正常工作。但是当我将它分配给PATHS_SHELL.它给了我一个带有以下文本的无限循环

/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 159: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 108: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 124: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 134: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 138: systemctl: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 146: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 149: ps: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 149: grep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 149: wc: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 150: [: : integer expression expected
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 159: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 108: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 124: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 134: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 138: systemctl: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 146: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 149: ps: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 149: grep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 149: wc: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 150: [: : integer expression expected
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 159: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 108: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 124: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 134: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 138: systemctl: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 146: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 149: ps: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 149: wc: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 149: grep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 150: [: : integer expression expected
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 159: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 108: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 124: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 27: seq: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 134: sleep: command not found
/home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh: line 138: systemctl: command not found

在这个无休止的输出之前,输出的是许多 shell 文件路径,这是预期的正确输出。例如

/usr/src/linux-headers-5.15.0-48/tools/testing/selftests/netfilter/ipvs.sh
/usr/src/linux-headers-5.15.0-48/tools/testing/selftests/netfilter/ipip-conntrack-mtu.sh
/usr/src/linux-headers-5.15.0-48/tools/testing/selftests/netfilter/conntrack_tcp_unreplied.sh
/usr/src/linux-headers-5.15.0-48/tools/testing/selftests/netfilter/nft_fib.sh
/usr/src/linux-headers-5.15.0-48/tools/testing/selftests/netfilter/nft_nat_zones.sh
/usr/src/linux-headers-5.15.0-48/tools/testing/selftests/netfilter/nft_meta.sh
/usr/src/linux-headers-5.15.0-48/tools/testing/selftests/netfilter/nft_zones_many.sh
/usr/src/linux-headers-5.15.0-48/tools/testing/selftests/netfilter/nft_concat_range.sh
/usr/src/linux-headers-5.15.0-48/tools/testing/selftests/netfilter/nf_nat_edemux.sh
/usr/src/linux-headers-5.15.0-48/tools/testing/selftests/netfilter/nft_nat.sh
/usr/src/linux-headers-5.15.0-48/tools/testing/selftests/netfilter/conntrack_icmp_related.sh
/usr/src/linux-headers-5.15.0-48/tools/testing/selftests/livepatch/test-shadow-vars.sh
/usr/src/linux-headers-5.15.0-48/tools/testing/selftests/livepatch/test-livepatch.sh

我使用的是 Ubuntu 22.04。

答案1

看来您使用了保留变量$PATH来索引字符串$PATHS_SHELL。该变量保存要搜索命令的目录列表,因此当您覆盖它时,将无法再找到任何脚本命令。因此会出现有关未找到命令的错误。

相关内容