I start up my terminal and Bash runs automatically.
When it does I get this error:
-bash: /Users/user/.bash_profile: line 1: unexpected EOF while looking for matching `''
-bash: /Users/user/.bash_profile: line 3: syntax error: unexpected end of file
How do I fix it?
There is an error in /Users/user/.bash_profile involving mismatched quotation marks. Look for mismatched quotes in the first line of that file.
Related
I have a unix shell script which I successfully run through Cygwin. As the script is to be used by someone with no IT knowledge I wanted it to be executed via batch file.
I created .bat file with the following content:
#echo off
C:\cygwin64\bin\bash C:\Sparkpay\MainScripts\converttocsv.sh
It fails to run though with the following errors:
C:\Sparkpay\MainScripts\converttocsv.sh: line 9: ls: command not found
C:\Sparkpay\MainScripts\converttocsv.sh: line 9: awk: command not found
C:\Sparkpay\MainScripts\converttocsv.sh: line 10: date: command not found
C:\Sparkpay\MainScripts\converttocsv.sh: line 15: cat: command not found
C:\Sparkpay\MainScripts\converttocsv.sh: line 15: sed: command not found
C:\Sparkpay\MainScripts\converttocsv.sh: line 15: uniq: command not found
C:\Sparkpay\MainScripts\converttocsv.sh: line 99: rm: command not found
C:\Sparkpay\MainScripts\converttocsv.sh: line 100: mv: command not found
I updated PATH to include c:\cygwin64\bin\bash.
Is there anything that I missed?
Thank you
I've tried to set up a folder called bin in my user directory. Sadly, my first attempt of appending the new directory was incorrect as I missed a ". I tried opening up the .bash_profile to try and delete my first attempt, but due to not really knowing what I was doing when saving I get these errors when I open the bash.
Last login: Mon Dec 23 11:13:39 on ttys000
-bash: /Users/daz/.bash_profile: line 2: unexpected EOF while looking for matching `"'
-bash: /Users/daz/.bash_profile: line 3: syntax error: unexpected end of file
darryls-mini:~ daz$ cat ~/.bash_profile
PATH=$PATH:~/bin"
PATH="$PATH:~/bin"
darryls-mini:~ daz$
The first line after cat is the incorrect one. This is the result of me trying to delete the bash_profile file and re-saving it using pico ~/.bash_profile
The error is in the following:
PATH=$PATH:~/bin"
which is causing the unexpected EOF while looking for matching `"'.
Observe the quoting. You probably wanted to say:
PATH="$PATH:~/bin"
Why don't you just edit the file and delete the line? Alternatively, this command will do it for you (assuming that your ~/.bash_profile is otherwise empty, as it seems to be in your post):
echo 'PATH="$PATH:~/bin"' > ~/.bash_profile
The error message is telling you what the problem is:
unexpected EOF while looking for matching `"'
You close the quotes without opening them:
PATH=$PATH:~/bin"
Change it to
PATH=$PATH:~/bin
or
PATH="$PATH:~/bin"
I'm using cygwin. I made a sh file like the following
#!/bin/sh
function bash {
local var="local variable"
echo $var
}
then I execute this file
./test.sh
The result returned is
./test.sh
./test.sh: line 2: syntax error near unexpected token `$'\r''
'/test.sh: line 2: `function bash {
I have no clue how to fix it and use the capability of writing function in bash scripts. Thank you in advance!
Regards,
The error message is trying to tell you there are CRLF line endings, and it doesn't like the CR ($'\r' being a bash way of representing CR, carriage return).
Using Cygwin, you need to do this before executing any bash file:
sed -i 's/\r$//' name_of_your_script.sh
Once done, you can use it normally. If you make any change in the code, use that line again.
This is because there is a problem with the CR when using bash files in Cygwin. This line eliminates those bothering CR and solves the problem.
I'm trying to run the script found here: http://blog.sebflipper.co.uk/2010/03/10/mysql-backup-as-separate-sql-files-with-rotation/comment-page-1/
bash /path/to/mysql-backup.sh
I'm getting the following errors:
/path/to/mysql-backup.sh: line 2:
: command not found
/path/to/mysql-backup.sh: line 4:
: command not found
/path/to/mysql-backup.sh: line 8:
: command not found
/path/to/mysql-backup.sh: line 10:
: command not found
/path/to/mysql-backup.sh: line 40: syntax error near unexpected token `{
'
/path/to/mysql-backup.sh: line 40: `function checkMysqlUp() {
Am I calling this command improperly?
Ok, it was the spaces, now I'm just getting the last 2 errors
Given the way the error messages are appearing, I think you downloaded the script with CRLF line endings and the shell is not liking this.
Use 'dos2unix' or 'dtou' or (if neither of the above is available, tr) to remove the carriage returns.
tr -d '\015' < /path/to/mysql-backup.sh > /path/to/other-mysql-backup.sh
Then try running:
/path/to/other-mysql-backup.sh
#! /bin/bash
This line at the top of the script isn't right. It should have no spaces.
It's not liking the blank lines in there. Are you sure when you maybe copied and pasted that you didn't inject ^M (carriage returns) or some other white-space character in there?
Makefile:
$(shell ./test.sh)
1st experiment: test.sh
echo "hi"
Error I get:
Makefile:1: *** missing separator. Stop.
2nd experiment:
test.sh
echo("hi")
Errors I get:
./test.sh: line 1: syntax error near unexpected token `"hi"'
./test.sh: line 1: `echo("hi")'
Doesn't make any sense...it looks as if 'Make' tries to impose its syntax on the shell script, but the shell script wants its own too.
try ./test.sh.
In the first experiment, the result is
hi
When you run make, the line $(shell ./test.sh) evaluates as hi, which Make doesn't know how to interpret.
In the second experiment,
./test.sh: line 1: syntax error near unexpected token `"hi"'
./test.sh: line 1: `echo("hi")'
You've written a shell script that doesn't have correct shell syntax, so it fails. It fails whether you run it or Make runs it.