0

I have been trying to use nohup with bash for loop and I came across this post here which was helpful and gave me an idea but my command is still not working properly. What I have right now looks like:

nohup sh -c 'for i in {0..9}; do spark-submit --class some.Code /some/Jar.jar --input_path /some/path/part-001"$i"* > test_log.log; done' &

when I run this the job fails with the following exception that the input path does not exists and shows me the path as:

/some/path/part-001{0..9}*

How can I get this to replace $i with the actual value of i and not the string {0..9}?

Thanks

ahajib
  • 12,838
  • 29
  • 79
  • 120
  • `{0..9}` is **bash** syntax. You cannot run it with `sh`. – Charles Duffy Sep 18 '20 at 16:33
  • @Lety, please don't point folks to the ABS "documentation". The irc.freenode.org #bash folks [wrote their own guide](https://mywiki.wooledge.org/BashGuide) specifically to stop people from learning bad habits from TLDP. – Charles Duffy Sep 18 '20 at 16:34
  • this could help: https://stackoverflow.com/questions/1445452/shell-script-for-loop-syntax – Lety Sep 18 '20 at 16:37

1 Answers1

1

IMHO sh is not an alias of bash on your system. If you start it like this:

nohup bash -c 'for i in {0..9}; do spark-submit --class some.Code /some/Jar.jar --input_path /some/path/part-001"$i"* > test_log.log; done' &

it will get working. As far as I can remember, the used syntax is the bash's own.

Ps: but I'm not sure, if the " marks around $i are needed. I prefer ${i} form.

Edit: if on your system sh is an alias of dash, then you could use this:

nohup sh -c 'for i in `seq 0 9`; do spark-submit --class some.Code /some/Jar.jar --input_path /some/path/part-001"$i"* > test_log.log; done &'
  • Using curly brackets, as in `${i}`, does not change the need for quotes -- `"${i}"` is more correct than `${i}` alone, just as `"$i"` is more correct than bare `$i`. See [When to wrap quotes around a shell variable?](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable), or the wiki page for shellcheck warning [SC2086](https://github.com/koalaman/shellcheck/wiki/SC2086). – Charles Duffy Sep 18 '20 at 16:42