Why ERROR when -e or -E are used?

How should -e or -E be used ?
I’m getting ERROR even for commands that look legit.

Search gave pretty little, so I suspect something on my system, but even in a pristine bash:

bash --noprofile --norc
bash-4.4$ julia --startup-file=no -E 'a = 1'
ERROR: UndefVarError: a not defined
bash-4.4$ julia --startup-file=no -E '1;'
1

and all of this is typed, no copy/paste.
Another one:

julia --startup-file=no -e 'using InteractiveUtils; InteractiveUtils.versioninfo()'
ERROR: syntax: incomplete: premature end of input

All of these commands work fine in the REPL, same julia, same terminal.

julia> using InteractiveUtils; InteractiveUtils.versioninfo()
Julia Version 1.6.1

It’s not recent; Quote from old notes, using julia-1.5:

julia -e "using LanguageServer; runserver()"
ERROR: syntax: incomplete: **premature** end of input 
julia -e "using Plots; s=1"
ERROR: syntax: incomplete: **premature** end of input 
Weird. Searched. Nevermind.

Any help would be appreciated.

All your examples work correctly for me on Linux in Julia 1.6.1. What system are you on, and how did you install Julia?

1 Like

Thanks for the answer. The system is openSUSE-Leap-15.2.
With the Generic Linux on x86 64bit, downloaded binary Download Julia,
it works, indeed.

Trying to automatize the procedure,
I forgot to append _build to distinguish between the build tree and the install tree.
(the prefix is the build directory; it should be different ?)

Procedure used to install the version that fails
bash

git fetch --all --prune
git tag  # to find the latest version

julia_version=1.6.1

git reset --hard #Forcibly remove any changes to any files under version control
git clean -x -f -d #Forcibly remove any file or directory not under version control
git checkout v$julia_version

# need to remove all files from the build 
# (cf. https://github.com/JuliaLang/julia/blob/9f22a3b4ce9c38bc73d7fc82aa0d61e286162c1a/doc/build/build.md)
# write prefix=/path/to/install/folder into Make.user and then run make install. 
# If there is a version of Julia already installed in this folder, 
# you should delete it before running make install.

build_dir=/usr/local/build/julia-${julia_version}
echo $build_dir
rm -rf ${build_dir}
make O=${build_dir} configure
# those errors are normal:
# find: ‘/usr/local/build/julia-1.6.1/base’: No such file or directory
# ...

cd ${build_dir}
echo "prefix=${build_dir}" > Make.user
make -j $(nproc)
make install

# quit this shell, to cleanup variables
exit

Let me fix it and report back.


Edit:

procedure with separate build and install directories
bash

git fetch --all --prune
git tag  # to find the latest version

julia_version=1.6.1

git reset --hard #Forcibly remove any changes to any files under version control
git clean -x -f -d #Forcibly remove any file or directory not under version control
git checkout v$julia_version

# need to remove all files from the build 
(cf. https://github.com/JuliaLang/julia/blob/9f22a3b4ce9c38bc73d7fc82aa0d61e286162c1a/doc/build/build.md)
write prefix=/path/to/install/folder into Make.user and then run make install. 
If there is a version of Julia already installed in this folder, you should delete it before running make install.

install_dir=/usr/local/build/julia-${julia_version}
echo $install_dir
rm -rf ${install_dir}
build_dir=${install_dir}_build
echo $build_dir
rm -rf ${build_dir}
make O=${build_dir} configure
# those errors are normal:
# find: ‘/usr/local/build/julia-1.6.0/base’: No such file or directory
# ...

cd ${build_dir}
echo "prefix=${install_dir}" > Make.user
make -j $(nproc)
make install

# quit this shell, to cleanup variables
exit

Same result.

In the end, a wrapper used to switch easily between versions did something like
/path/to/bin/julia $@,
Double quotes are needed around the $@:

#! /bin/sh
# ...
/path/to/bin/julia "$@"