Setting up environment variable in linux - linux

While installing UIMA I got this steps in readme file
* Set JAVA_HOME to the directory of your JRE installation you would like to use for UIMA.
* Set UIMA_HOME to the apache-uima directory of your unpacked Apache UIMA distribution
* Append UIMA_HOME/bin to your PATH
* Please run the script UIMA_HOME/bin/adjustExamplePaths.bat (or .sh), to update
paths in the examples based on the actual UIMA_HOME directory path.
This script runs a Java program;
you must either have java in your PATH or set the environment variable JAVA_HOME to a
suitable JRE.
I opened /etc/environment and perfomed this changes:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/UIMA_HOME/bin"
JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386"
UIMA_HOME="/root/Desktop/karim/software/UIMA/UIMA_SDK_1.4.5"
after that executed:
UIMA/UIMA_SDK_1.4.5/bin# ./documentAnalyzer.sh
which gave this error:
./documentAnalyzer.sh: 2: .: Can't open /bin/setUimaClassPath.sh
documentAnalyzer.sh code :
#!/bin/sh
. "$UIMA_HOME/bin/setUimaClassPath.sh"
if [ "$JAVA_HOME" = "" ];
then
JAVA_HOME=$UIMA_HOME/java/jre
fi
"$JAVA_HOME/bin/java" -cp "$UIMA_CLASSPATH" -Xms128M -Xmx900M "-Duima.home=$UIMA_HOME" "-Duima.datapath=$UIMA_DATAPATH" -DVNS_HOST=$VNS_HOST -DVNS_PORT=$VNS_PORT "-Djava.util.logging.config.file=$UIMA_HOME/Logger.properties" com.ibm.uima.reference_impl.application.docanalyzer.DocumentAnalyzer
What is the mistake here? I guess I set environment variable correctly

I think the answers given about adding the $ to the variable UIMA_HOME in your PATH variable are correct, but, I think you are also lacking the EXPORT command for your variables.
Look, after you set their values, you should also writhe this in /etc/environment:
export UIMA_HOME
export JAVA_HOME
export PATH
That way, you would be able to use them later (always remember to fix the PATH variable with the $UIMA_HOME as well).
If this does not work, try rebooting your computer after setting the variables as I said.
In the case that does not work either, try repeating the process and in a console (after doing everythin all over again) try using the following command:
source /etc/environment
Fianlly, if that does not work, try setting the variables in the file called /etc/profile (do the same process: setting the varialbes and exporting them), and this should work.

The order of variable assignments in your /etc/environment is wrong; in order to use $UIMA_HOME in the PATH=..., you have to define UIMA_HOME afore, e. g.
UIMA_HOME="/root/Desktop/karim/software/UIMA/UIMA_SDK_1.4.5"
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$UIMA_HOME/bin"
JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386"

Related

how to set the LUA_PATH and LUA_CPATH for the zerobrane studio in linux

I want to add a module path for all of my project in zerobrane. I add following code into the user.lua.
LUA_PATH=LUA_PATH .. ';mypath' or
package.path=package.path .. ';mypath'
It can't work. how can I do it ?
PS
I don't want to set the package.path at the begin of all the project.
When Lua starts, it initialises package.path and package.cpath with values of LUA_PATH and LUA_CPATH environment variables. Setting up these environment variables will be one clean way to set paths. Appending LUA_PATH's value with a double semi-colon will make Lua append the default path to the specified path.
Using bash on Linux, you can set the paths by adding these lines to the end of ~/.bashrc file. For example:
## final ;; ensure that default path will be appended by Lua
export LUA_PATH="<path-to-add>;;"
export LUA_CPATH="./?.so;/usr/local/lib/lua/5.3/?.so;
/usr/local/share/lua/5.3/?.so;<path-to-add>"
Hope it helps.
You can set LUA_PATH and LUA_CPATH before starting ZeroBrane Studio and it should pass those values to all the projects you run or debug from the IDE.
I add following method into the /opt/zbsstudio/lualibs/mobdebug/mobdebug.lua file.
package.path = package.path .. ';my_path/?/init.lua'
package.cpath = package.cpath .. ';my_path/?.so'
But I'm not sure that's the best way.

Using Linux environmental variables as a path in Perl script

I am trying to use an environmental variable to point to a file, run it through a subroutine and associate it with a variable. I managed it with Windows but I cannot get the syntax working for Linux..
This is what I have:
my $config = read_config("$ENV{APP_HOME}/config/APP-linux.cfg");
my script dies when reaching this line with the error:
Use of uninitialized value $ENV{"APP_HOME"} in concatenation (.) or string at ./XXXXX.pl
APP_HOME is defined as an environment variable (confirmed using set). What am I doing wrong?
In bash, = simply creates a shell variable. These are not automatically exported to the environment. You need to do that explicitly.
Set a shell variable:
$ AA=hello
Set and export another one (in a single statement):
$ export BB=there
Start a new process:
$ bash
Voila! Only the exported variable is inherited by the new process:
$ echo "[$AA] [$BB]"
[] [there]
Note that set does not set a variable. set AA=hello does not do what the Windows shell does.
Okay, the solution was of my own stupidity. I set the variable in .bashrc using:
APP_HOME=$HOME/APP/DATA/STORAGE; export FINE_DIR
The RAPID_DIR had no right to be there. Was a remainder of a copy/paste and poor oversight... Changes FINE_DIR to APP_HOME and all is good.
Thankyou for all the guidance!

Set Enviroment Variable that contains two paths interelated paths

I am trying to create a custom environment variable that uses python to execute a py file.
Here is an example of what I have
export VAR=${VAR}:"/usr/bin/python2.7 /home/user/file"
When I use the variable I get the output:
bash: :/usr/bin/python2.7: No such file or directory
If I echo the variable I get the output:
/usr/bin/python2.7 /home/user/file
EDIT:
Trying "$VAR" gives me the output
bash: :/usr/bin/python2.7 /home/user/file: No such file or directory
If I run just this /usr/bin/python2.7 /home/user/file it works
I think an alias is more appropriate for all kinds like this (you may consider a more suitable name for the alias)
alias var="/usr/bin/python2.7 /home/user/file"
If you want to stick with your version you have to tell your shell to evaluate the content of VAR.
For this you just have to invoke
eval ${VAR}
By the way, why do you append the string "/usr/bin/python2.7 /home/user/file" to VAR instead of overwriting the content of VAR?

How to change the language of my git?

My ˋgitˋ is in german, it says:
ˋAuf Zweig masterˋ
instead of
On branch master
with git status.
What's the reason for this?
Probably you locale is german. You can see it by locale. Try to change it by: export LANG="en_US.UTF-8"
The reason for this is that your command line language is set to German.
So when you do:
echo $LANG
you will see:
de_DE.UTF-8
To change this, do:
echo "export LANG=en_US.UTF-8" >> ~/.bashrc
assuming your standard shell is bash.
Don't forget:
source ~/.bashrc
Sometimes changing the LANG environment variable alone is not good enough.
You may also need to add LC_ALL
export LC_ALL=en_US.UTF-8
According to The IEEE and The Open Group - Environment Variables.
It is because the environment variables starting by LC_* will be used first by your system before LANG:
The values of locale categories shall be determined by a precedence
order; the first condition met below determines the value:
If the LC_ALL environment variable is defined and is not null, the
value of LC_ALL shall be used.
If the LC_* environment variable (LC_COLLATE, LC_CTYPE, LC_MESSAGES,
LC_MONETARY, LC_NUMERIC, LC_TIME) is defined and is not null, the
value of the environment variable shall be used to initialize the
category that corresponds to the environment variable.
If the LANG environment variable is defined and is not null, the
value of the LANG environment variable shall be used.
If the LANG environment variable is not set or is set to the empty
string, the implementation-defined default locale shall be used.
To change it permanently, you need to paste the code above into your favourite shell configuration file (probably ~/.bashrc or ~/.zshrc)
Then to apply the modification do:
$ source ~/.bashrc
or
$ source ~/.zshrc
Otherwise, just open a new terminal.
In my case, setting LANG or LC_ALL was not enough. I also had a LANGUAGE environment variable which was set to en_GB:en_US:de. Despite the ordering, which is presumably an order of preference, it resulted in a German language response from git and other commandline-programmes. When I changed it to en_GB:en_US, git and other programmes became English.
As explain in #Tom comment, it is possible to add alias. In my case, I add in my Ubuntu ~/.bash_aliases
alias giten='LANGUAGE=en_GB:en_Us git'
so if I use git, it is in my language, if I use giten, it is in english
NOTA: by this way, the auto-completion is lost

Read / Run Environment Variables in a text file

I have an app which runs and reads a text configuration file.
This points to several locations of configurations / outputs etc.
Is it possible to use environmental variables inside the text configuration file, rather than hardcoded paths?
LogFilePath=$LOG_FILE_PATH
vs
LogFilePath=/home/user/logs
When running, the application fails as it cannot expand the Environment Variable.
It will be sourced inside the shell before the application is run.
Thanks!
Recently I used this in a (bash) script:
#!/bin/bash
# ...
source config.file
# ...
Where config.file had lines like this:
export ORIG_PATH="${PATH:-.}:/bla/bla"
export SOMESETTING="${SOMEVAR:-"somedefault"},somedata"
...
So the ${parameter:-word} thing worked well for me: use default values, if parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted. (From man bash.)
HTH

Resources