zsh parse error: "(eval):1: parse error near `)'" - zsh

When I open terminal, I receive this message:
Last login: Fri Jan 17 11:02:25 on ttys000
(eval):1: parse error near `)'
(eval):1: parse error near `)'
It prints twice, but I only have four ")" in my .zshrc file, and none of them seem to be causing any issues. I've looked around the web for solutions, but I haven't found many that seem to address this problem.
My .zshrc file looks like this:
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
(Some code removed for brevity...)
# Which plugins would you like to load?
source $ZSH/oh-my-zsh.sh
# My personal Add-ons:
# open VSCode via "code"
function code {
if [[ $# = 0 ]]
then
open -a "Visual Studio Code"
else
local argPath="$1"
[[ $1 = /* ]] && argPath="$1" || argPath="$PWD/${1#./}"
open -a "Visual Studio Code" "$argPath"
fi
}
Thanks!

Related

What does `source` do when given a directory?

I often happen to run a command like source mydirectory, where mydirectory is a ...directory, and not a shell script file (I guess I'm not that good at predicting autocompletion :p)
What puzzles me is that zsh does not complain, and returns 0 as status code; although that does not seem a normal call to source AFAIK.
# in zsh shell
# create an empty dir
$ mkdir /tmp/mydir
# "source" it
$ source /tmp/mydir && echo "success"
# output: 'success'
Meanwhile, bash will complain when asked to "source"
# in bash
$ source /tmp/mydir/ && echo "success"
# output: 'bash: source: /tmp/mydir/: is a directory'
Does someone know why this is a valid call in ZSH?
References I looked in
SO itself
the documentation of ZSH builtin commands https://zsh.sourceforge.io/Doc/Release/Shell-Builtin-Commands.html
multiple tutorials about source
... to no avail

Why does my .zshrc file throw this error when I source it?

I installed zsh on my mac but I get this error when I try to source it:
Last login: Sat Nov 20 15:54:12 on ttys004
➜ ~ source zsh
[2] 55808
/usr/local/bin/zsh:1: parse error near `)'
/usr/local/bin/zsh:1: bad pattern: ^#^#^#^#^#^Y^#^#^#H^#^#^#__PAGEZERO^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^A^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^Y^#^#^#(^B^#^#__TEXT^#^#^#^#^#^#^#^#^#^#^#^#^#^#^A^#^#^#^##^H^#^#^#^#^#^#^#^#^#^#^#^#^#^##^H^#^#^#^#^#^E^#^#^#^E^#^#^#^F^#^#^#^#^#^#^#__text^#^#^#^#^#^#^#^#^#^#__TEXT^#^#^#^#^#^#^#^#^#^#\M-<O^#^#^A^#^#^#\M-q
/usr/local/bin/zsh:1: parse error in command substitution
[2] + 55808 exit 1 ����X�
I copied the zshrc.zsh-template from templates as my .zshrc file so I don't even know if the problem is with zsh. It just happens when I run source zsh. I can't figure out what causes this or how to fix it.
The proper source command is source ~/.zshrc

terminal after installing R using homebrew

After installing R using homebrew on mac following the instructions from here : https://www.datacamp.com/community/tutorials/installing-R-windows-mac-ubuntu . When I open the terminal I get these :
-bash: /Users/myname/.bash_profile: line 27: syntax error near unexpected token `category="LC_ALL",'
-bash: /Users/myname/.bash_profile: line 27: `Sys.setlocale(category="LC_ALL", locale = "en_US.UTF-8")'
so how could I fix/get rid of these from appearing on the terminal .
I think this has something to do with :
$ echo "export LC_ALL=en_US.UTF-8" >> ~/.bash_profile
$ echo "export LANG=en_US.UTF-8" >> ~/.bash_profile
$ echo "export PATH=/usr/local/bin:$PATH" >> ~/.bash_profile && source ~/.bash_profile
The instructions that you link to say to do this in Step 3 to add stuff to your ~/.bash_profile:
echo 'Sys.setlocale(category="LC_ALL", locale = "en_US.UTF-8")' >> ~/.bash_profile
I think that is wrong. That is R code, not bash code, so it shouldn't go in ~/.bash_profile. It should go in ~/.Rprofile instead.
Remove line 27 (the one that says Sys.setlocale(...)) from your ~/.bash_profile and add it to your ~/.Rprofile file instead.
And then send DataCamp an email telling them that their R installation instructions have a significant error in them.

Error while running a .sh script via QProcess

I have written a QT GUI program where pressing a button will execute a .sh script. The contents of the script is-
echo -e 'attach database 'testdatabase.db' as 'aj';\n.separator ","\n.import ora_exported.csv qt_ora_exported' | sqlite3 testdatabase.db
basically the script will import a .csv to an sqlite database. And when the script file (script.sh) is run manually from linux terminal ($./script.sh) it successfully imports the .csv file into the database table.
But, when I call the script from my QT program
void MainWindow::on_importButton_clicked()
{
QProcess process;
process.startDetached("/bin/sh",QStringList()<<"/home/aj/script.sh");
}
it compiles successfully but gives an error message in console when the button is pressed at runtime.
Error: near line 1: near "-": syntax error
Error: cannot open "ora_exported.csv"
what could be causing this ???
EDITED
I have changed my .sh script now to--
echo -e 'attach database 'testdatabase.db' as 'aj';\n.separator ","\n.import /home/aj/ora_exported.csv qt_ora_exported' | sqlite3 testdatabase.db
Thus providing the path to my ora_exported.csv. As a result the runtime error [Error: cannot open "ora_exported.csv"] has gone but the other message [Error: near line 1: near "-": syntax error] is still coming.
Same as was observed in previous case, using ./script.sh is successfully importing data to sqlite3 db table file but QProcess is unable to.
echo is a built in command of a shell that may behave differently.
E.g. take this test script: echotest.sh
echo -e "123"
Now we can compare different results:
$ bash echotest.sh
123
$ zsh echotest.sh
123
$ dash echotest.sh
-e 123
You are probably on some Ubuntu-like OS, where /bin/sh redirects to dash. That would explain the error around "-". So if you are using echo, set you shell specificially or ensure that your script works on all common shells.
Additionally, you are messing up your quotations
echo -e 'attach database 'testdatabase.db' as 'aj';\n.separator ","\n.import /home/aj/ora_exported.csv qt_ora_exported'
results in (no quotations in the first line)
attach database testdatabase.db as aj;
.separator ","
.import /home/aj/ora_exported.csv qt_ora_exported
but you pobably want
echo -e "attach database 'testdatabase.db' as 'aj';\n.separator ','\n.import /home/aj/ora_exported.csv qt_ora_exported"
It looks strange that you are using external script to update database!
why you don't pass "ora_exported.csv" file name as a script argument? This would help solve the problem.
I was talking (typing) about this solution:
void MainWindow::on_importButton_clicked()
{
QProcess::startDetached("/bin/sh",
QStringList()<<"/home/aj/script.sh",
"<location of: 'ora_exported.csv' file>");
}

Cygwin: Unable to find Java path.

I am using cygwin on windows 7 env and it is unable to locate java, error message i get is that
ERROR: /cygdrive/c/Program
Files/Java/jdk1.6.0_22 does not exist!
wired path is if I do echo $JAVA_HOME then it shows me
$ echo $JAVA_HOME
/cygdrive/c/Program Files/Java/jdk1.6.0_22
not sure what is happening here, any suggestions?
The problem is that the pathname contains spaces. You need to escape the spaces as described here:
http://www.cygwin.com/faq/faq.using.html#faq.using.filename-spaces
Adding this line to your .bashrc should do it:
export JAVA_HOME='/cygdrive/c/Program Files/Java/jdk1.6.0_22'
Edit: You could try running this script which I found in this blog post:
case "`uname`" in
CYGWIN*) cygwin=true ;;
esac
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
JAVA_HOME=`cygpath --windows "$JAVA_HOME"`
CLASSPATH=`cygpath --windows --path "$CLASSPATH"`
fi
Use the old school way:
export JAVA_HOME=/cygdrive/c/Progra~1/Java/jdk1.6.0_22
It worked for me.

Resources