1

I'm trying to write a bash function in .bash_profile with a parameter that will run a script on my sql and test it, but I get the following error when trying to invoke it:

$ sqltest() ~/Downloads/hw5-2.sql
-bash: syntax error near unexpected token `~/Downloads/hw5-2.sql` 

The parameter is the file path. What I have right now (also have tried "$1" w/o quotes):

sqltest() { java -cp h2-1.4.200.jar org.h2.tools.RunScript  -checkResults -url jdbc:h2:mem:test -script "$1" -continueOnError ; }
10
  • If that guess is wrong, I'd suggest running set -x to enable trace logging, reproducing the error, and showing us how you did it with a transcript including both the command you ran and the exact text that resulted (up to and including the error message itself; any trace logs that relate to printing your prompt or other such local hooks don't need to be included). Commented Feb 24, 2020 at 16:00
  • (BTW, "$1" inside quotes is correct). Commented Feb 24, 2020 at 16:01
  • I am running as sqltest() ~/Downloads/hw5-2.sql Commented Feb 24, 2020 at 16:01
  • Just run sqltest ~/Downloads/hw5-2.sql. The () is not part of the function name. Commented Feb 24, 2020 at 16:01
  • 1
    @Jetchisel, the expansion is done before the function is started, so ~ works fine. It would be a problem if they were running sqltest "~/Downloads/hw5-2.sql", but they aren't. Commented Feb 24, 2020 at 16:02

1 Answer 1

1

Leave the parenthesis out of the function call; they're only part of function definition syntax:

sqltest ~/Downloads/hw5-2.sql
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.