shell


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:
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.
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.

Related Links

Unset variables and move on to the next line if condition not met
Re-writing a .bat in .sh [duplicate]
Unix Korn shell retrieve the latest file name with space
Docker CMD evaluation with ENTRYPOINT
How do I run the Hetionet v1.0 docker container?
Shell Error while trying to perform a IF statement
Is there a way to convert all the columns (space separated) of a file into rows?
Remove junk characters from a utf-8 file in Unix
How to send a binary (ebcdic format) file with variable blocks (each record has variable length), from a unix system to a unix mainframe through NDM?
Delete first and last character from from each line of a txt file
Shell script for cron to send an email if the command produces any output
Teamcity with Subversion post commit script on windows
shell: how to pagination file with code highlight?
Read and print Line between two tags
Whats the difference between $ExecutionContext.SessionState.Path.CurrentLocation and $pwd in Powershell?
Pro*C unable to read parameter passing from korn shell script

Categories

HOME
windows
google-cloud-platform
webdriver
ns-3
flex
yahoo-finance
spring-data-redis
alarm
jtextpane
trac
pkcs#11
ibeacon-android
mautic
datastage
onedrive-api
plink
libusb
powershell-v5.0
google-data-studio
symfony-console
visual-glitch
inno-download-plugin
data.stackexchange.com
mat
entity-relationship-model
spotipy
paperjs
event-flow
postback
cognos-bi
database-comparison
roblox
swagger-php
magento-1.9.2.4
nohup
projects-and-solutions
resolution
skylink
jide
nanoc
twilio-click-to-call
opengl-4
janus
google-photos
ampps
seek
mta
beamer
scaffolding
riot
cortex-m
findfirst
jnlua
assertion
dllimport
oracle-spatial
sapscript
ansi
git-ftp
showdialog
browserify-shim
spy++
linkedin-jsapi
ray
tinyxml
accesscontrolexception
ecslidingviewcontroller
visual-studio-express
mysql-error-1044
kendo-dataviz
hidapi
script#
observium
flex++
kaleidoscope
insert-id
cascadingdropdown
android-sdk-2.3
dajaxice
thttpd
gobject-introspection
w3c-geolocation
http-daemon
codebase
metaweblog
objective-j
load-time
dot-emacs
aspmenu
blender-2.49
request-headers
qtabbar
ifilter
wspbuilder
netbeans6.1

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App