PasLeChoix
PasLeChoix

Reputation: 311

shell script "syntax error: `done' unexpected."

I am new to linux shell scripting, here is a snippet I want to use:

while IFS='' read -r line || [[ -n "$line" ]]; do
echo ""
echo ""
echo ""
echo "Counting the table : $line"
eval "hive -e 'select count(*) from $line'"
done < "$1"

I name it as count_row.sh. Here is the usage:

$ ./count_row.sh t1.csv > row.txt

t1.csv basically contains some table's name each line.

I got an error below:

syntax error at line 7: `done' unexpected

But the snippet I borrowed here was marked as accepted solution, presumably it is correctly written. So what am I missing here? Thank you very much.

Upvotes: 0

Views: 694

Answers (1)

OneCricketeer
OneCricketeer

Reputation: 191844

If you have table names each on their own line, that is a regular text file, not a csv, by the way.

Try not using eval, though, and instead run the statement inline.

#!/bin/bash

while IFS= read -r line; do
  echo "${line}: $(hive -e 'select count(*) from ${line}')"
done < "$1"

If you want to test your script better, I would suggest a for loop over a hard-coded list of tables.

Upvotes: 1

Related Questions