0

We have a simple shell script: myTest.sh, the contents are as follows:

#!/bin/sh
################### file begins########################
. ./backupConfig.p.properties
echo "success"
################### file ends########################

The contents of backupConfig.p.properties are as follows:

####################################### file starts ########################

# Prod database connection details
database_env="OXDB”

### <some comments> ####

softLocation=/opt/apps/ibm/

### <some comments> ####
tablesList="Tab1 Tab2 Tab3"
### <some comments> ####

####################################### file ends ########################

The problem is whenever we tried to run the shell script, it always threw error:

$ sh myTest.sh
./backupConfig.p.properties: line 11: Tab1: command not found
success

We tried to remove comments in the line above and below, we checked for empty spaces in this line - nothing helped to solve the problem. Only thing that worked was, we cut this line from its current position and pasted 3 lines below and it worked. Can someone please help to explain why this error and why changing the line position worked?

  • 1
    The quote mark at the end of the database_env line looks really suspicious -- is that a copy/paste artifact, or does your actual properties file have it as well? I suspect that the opening quote for database_env is not getting closed until it reaches the opening quote for tablesList, at which point the shell sees "Tab1" as a command to execute. – Jeff Schaller Sep 25 '15 at 16:58
  • Hi Jeff, you Nailed it! that was it, i don't know how after doing a cut and paste two lines below it was working, but as soon as i changed the double quotes per your suggestion, it started working :-) Many thanks! – JavaTec Sep 29 '15 at 16:53
0

The issue turned out to be an imposter double-quote at the end of the database_env line. The shell saw the opening double-quote, then a string starting with

OXDB”

then a newline, some more text, and finally "ending" with the intended opening quote on the tablesList line.

Besides having another set of eyes look at it, one helpful hint for future errors like this is to focus closely on the text preceding the error message; in this case, the shell saw Tab1 as a command to execute when the author intended it to be a variable assignment.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.