I had a similar problem to this with Python using readlines() but I'm not sure if it's the same here.

The read command is hanging my bash script.

generate_email()
{
    # --- Arguments
    oldrev=$(git rev-parse $1)
    newrev=$(git rev-parse $2)
    refname="$3"

    # ... some code ...
}

# ... more code ...

while read oldrev newrev refname
do
    generate_email $oldrev $newrev $refname
done

Any ideas on how to fix this?

有帮助吗?

解决方案

You're not telling read to read from anything. So it's just waiting for input from stdin.

If you're wanting to read from a file, you need to use read like so:

while read -r oldrev newrev refname; do
  generate_email "$oldrev" "$newrev" "$refname"
done < /path/to/file

Note the < /path/to/file. That's where you're actually telling read to read from the file.

If you're wanting to read from an input stream, you can use while read like so:

grep 'stuffInFile' /path/to/file |
while read -r oldrev newrev refname; do
  generate_email "$oldrev" "$newrev" "$refname"
done

其他提示

I'd say it's not hanging, but just waiting for input.

Watch out though and make sure that generate_email does not read from the same input stream.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top