Quantcast
Viewing all articles
Browse latest Browse all 6153

Why does the for loop in this shell script perform the first iteration twice before doing the second one?

I have a bash script:

#! usr/bin/env bash# test bash script to call python scriptscd ~/pythonfor ((i = 1; i <= 2; i++)); do python3 test_0$i.py; donecd ~/bash

that pulls test_0x.py files from the python directory and runs them in order.test_01.py is a single print statement, whereas test_02 is a for loop.

I was expecting it to:

  1. navigate to ~/python
  2. run test_01.py
  3. run test_02.py
  4. navigate back to ~/bash

the bash script runs test_01.py, then test_01.py again, and only then test_02.py.is this some quirk of shell-scripts i am simply too green to anticipate, or is there something wrong with my — albeit very basic — code?

I am using an ubuntu terminal through windows subsystem for linux, if that affects things.


Viewing all articles
Browse latest Browse all 6153

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>