How do I fix a syntax error in my bashrc function?

0
12
Asked By QuirkyFox87 On

I'm trying to add a function to my .bashrc, but I'm hitting a wall with errors related to quotes. The terminal returns these messages: -bash: .bashrc: line 142: unexpected EOF while looking for matching `'' and -bash: .bashrc: line 145: syntax error: unexpected end of file. Here's the function I'm attempting to add:

```bash
dwdb() {
local query="SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME;"
sqlcmd -S link -d table -U user -P 'password' -C -Q "$query"
}
```

5 Answers

Answered By SillyOtter92 On

It looks like you're facing an issue with quote matching in your script. The error you're getting suggests that there might be a missing quote earlier in your .bashrc file, potentially before your function. Check the lines above line 140 to see if any quotes are unclosed.

Answered By CuriousLlama66 On

Make sure you're formatting your code properly. Sometimes, misalignment or improper record of quotes can lead to these errors. Also, the error may stem from a function defined earlier in the script that has some sort of quote mismatch.

Answered By TechieTurtle31 On

Have you tried using `shellcheck`? It's a great tool for detecting syntax errors in your shell scripts. It might point you directly to where the issue lies.

Answered By CleverPanda45 On

It seems like your function might need a declaration. Try redefining your function like:
```bash
function dwdb() {
local query="SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME;"
sqlcmd -S link -d table -U user -P 'password' -C -Q "$query"
}
``` This could help clarify the syntax.

Answered By EagerBee23 On

You're right about `unexpected EOF while looking for matching `''`—it's indicating a problem with quotes. Check for any stray single quotes or backticks that might be left unclosed in your .bashrc file.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.