-1

I was working on a shell script where I came across this problem that I couldn't solve

The following command is supposed to find all shell files in /.

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

If I execute the command without assigning it to a variable, it works just fine. But when I assign it to PATHS_SHELL. It gives me an endless loop with the following text

/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

Before this endless output, the output is many of the shell file paths which is the expected and correct output. e.g.

/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

I am using Ubuntu 22.04.

4
  • 8
    Please edit your question and show us the actual script you are using. The errors cannot be produced by the command you show, they refer to lines 27, 134 and 138 of /home/kibnakamoto/workspace/Astrobee/scripts/daemon/astrobee/status_leds.sh. I am guessing that you are later using the variable, most probably using it without quoting it correctly, and that produces the errors, but we can't help without seeing the rest of the script or, even better, a small part of the script that we can run to reproduce the errors.
    – terdon
    Commented Dec 6, 2022 at 16:46
  • 1
    Possibly you meant readarray -td '' sh_scripts < <(sudo find / -name '*.sh' -type f -print0) to assign the list of the paths of regular files with names ending in .sh to a variable. PATHS_SHELL=$(sudo find / -name '*.sh') doesn't make any sense. Commented Dec 6, 2022 at 16:52
  • Or you've used $PATH as a variable to index into $PATHS_SHELL? Commented Dec 6, 2022 at 21:51
  • @roaima, that was the problem, the endless loop was from a cat x y >> x. Thank you. Commented Dec 7, 2022 at 0:25

1 Answer 1

1

It seems you used the reserved variable $PATH to index across your string $PATHS_SHELL. This variable holds the list of directories to be searched for commands, so when you overwrote it, none of your scripted commands could be found anymore. Hence the errors about commands not being found.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.