0

I have an "input_file" which contains a few entries. I read the input_file as shown below and pass each line as an argument to some_other_script.sh
The script some_other_script.sh takes the argument, passes it to ant and then performs some processing.
Problem is that it only reads the first line and then stops processing. In fact, it also prints "Did the code return" but nothing after that.
If I remove the "ant" statement in some_other_script.sh, it works fine but of course, that is not what I want.

while read line
do
  echo $line
  ./some_other_script.sh $line
  echo "Did the code return"
done < "input_file"

I have tried a number of combinations, but none of them have worked.

souser
  • 5,868
  • 5
  • 35
  • 50
  • What environment is this in? Maybe some issue with line endings? – Kaz Aug 08 '19 at 22:41
  • 2
    It's possible that there is a process in your `some_other_script` that's consuming `STDIN` (e.g. `ssh` will do that). You may need to use an alternate file descriptor in the script in your question. See [BashFAQ/089](http://mywiki.wooledge.org/BashFAQ/089) for more information. – Dennis Williamson Aug 08 '19 at 22:55
  • One thing you might do as a debugging tool: Replace `< "input_file"` with `< <(while IFS= read -r line; do printf '%s\n' "$line" >&2; printf '%s\n' "$line"; done <"input_file")`, so it prints each line to stderr at the same time as it sends it to the pipeline. That way, you can see whether and when the content is being consumed. If it's consumed during `some_other_script`, that lets the blame be placed. :) – Charles Duffy Aug 08 '19 at 23:30

1 Answers1

0

When I read the contents into an array and then process it, it works just fine. I am not sure I understand what the difference it. If there is a better solution, do let me know.

arr=()
while IFS='' read -r line; do
  arr+=("$line")
done < "input_file"

for line in "${arr[@]}"
do
  ./some_other_script.sh $line
done
souser
  • 5,868
  • 5
  • 35
  • 50
  • Isn't there a bash builtin that will do what the first part of your script does, that is, reading a file contents into an array, namely the bash builtin `mapfile`? –  Aug 08 '19 at 22:52
  • I believe `mapfile` is available in bash 4 ; I am running this on a server that uses bash 3 – souser Aug 08 '19 at 22:54
  • @Charles "this" being the array declaration ? – souser Aug 08 '19 at 22:57
  • @CharlesDuffy I added ` – souser Aug 08 '19 at 23:03
  • Please provide a reproducer. When we don't have a copy of `some_other_script.sh`, we can only guess at what it might be doing; that said, the most obvious, clear, and common way to make a future `read` fail is *to consume that content first*, which is what ` – Charles Duffy Aug 08 '19 at 23:06