Unable to Set VISUAL environement variable in bashrc - linux

I am trying to set the VISUAL and EDITOR environment variables in a server for default usage with crontab.
When I do a manual export VISUAL=vim, things work perfectly.
But when I add the lines
EDITOR=vim
VISUAL=vim
to my .bashrc file and logout and re-login, I don't see any changes on opening crontab -e.
If later I do echo $VISUAL, I get the response vim
What am I doing wrong here?

You have to put:
export EDITOR=vim
export VISUAL=vim
in your .bashrc file to make the variables available to the subprocess.

Works perfectly in my environment ubuntu 12.04.!

Related

Linux $PATH variable autoupdates

I have a problem on my Ubuntu 18.04 , I set PATH variable , and it works fine but after some time it reverts my changes. I do something like:
export $PATH=$PATH:/my/dir/bin .
You could add it to your .bashrc, and make it permanent.
Using any text editor, edit ~/.bashrc, and add the line you need.
Then source it, source ~/.bashrc.
With the export command the new PATH variable will be only available at the current terminal session. To make it permanent over the different sessions you will need to add it to the ~/.bashrc file.
That call will only work for your terminal session, you need to edit your ~/.profile or ~/.bashrc file, and put the path in there then start a new terminal session

Default bash environment changed. How do I revert it to default?

I am using AWS EC2 along with the CodeStar services.
I wanted to add the path to maven's binary to the PATH environment variable.
So I wrote it to the /etc/environment file and executed the command:
source /etc/environment
But it has now changed the default environment of the bash shell and now I am not able to execute any command. Even for a command like ls it gives output -bash: command not found
How do I revert back to the default settings. I tried whatever my brain could think of. But nothing helped. Would be glad to hear from the community.
In order to revert back to the default settings:
As #Cyrus wrote you should update the PATH variable
In the bash shell run the following command:
PATH="/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin"
Undo the changes to the /etc/environment
edit the /etc/environment using the same method you used before, and remove the PATH line you added to the file
You can use sudo vi /etc/environment or any other editor you prefer
Note: In my AWS machine, the /etc/environment file is empty.

Cannot create permanant environment variable in Ubuntu

I'm trying to create a permanent environment variable on Ubuntu.
I tried the following:
export SASS_LIBSASS_PATH=/usr/local/lib/libsass
When I opened a new terminal and used 'printenv', I found the variable disappeared!
I also tried to make it work by appending:
SASS_LIBSASS_PATH="/usr/local/lib/libsass"
to the end of the file in /etc/environment, and then used:
source /etc/enviroment
That did not work!
UPDATE:
I then tried editing my ~/.profile file:
SASS_LIBSASS_PATH="/usr/local/lib/libsass"
that did not work.
I then tried instead appending the following at the end of ~/.profile file:
export SASS_LIBSASS_PATH="/usr/local/lib/libsass"
that too did not work!
How can I make a permanent system variable?
export only sets the environment variable in your current shell session and any child processes started by that shell session. It is certainly not "permanent". The only way to set an environment variable for future shell sessions is to add the export command to a shell start-up file. Your best bet is probably to put it in ~/.profile (unless the file ~/.bash_profile exists).

Eclipse doesn't use the path set in .bashrc

whenever I run eclipse from the shortcut I am unable to correctly build some of my projects because the PATH variable that I configured in .bashrc doesn't get used.
When I run eclipse from my terminal, I can build all my projects perfectly fine because it's running through the correct shell.
The problem is that I want to use the PATH variable from my .bashrc without permanently having a terminal open. I tried this before, but every day I accidentally close the terminal that's running eclipse by accident and lose all my unsaved code.
Can anyone help me?
Your tooling probably utilizes the embedded eclipse terminal. This terminal does not start providing your login/user shell. So you need to set the eclipse terminal in your Eclipse preferences to start as --login shell:
Go to:
Preferences -> Terminal -> Local Terminal
and set
"Arguments" to "--login"
restart Eclipse and your users $PATH should be used from now on.
Edit /usr/share/applications/eclipse.desktop with write privileges, i.e. sudo gedit /usr/share/applications/eclipse.desktop
Change the setting Exec=/usr/bin/eclipse to Exec=bash -ic "/usr/bin/eclipse" and save
The underlying issue is that .bashrc is not loaded in a non-interactive shell. When you start Eclipse normally clicking on its symbol, .bashrc quits early. This solution applies to all programs that are defined by a .desktop file.
In contrast, bash -i opens an interactive shell, -c "" runs a command in that shell.
I can think of two options for this problem:
write a small script, export those vars or source your .bashrc before you start your eclipse.
define those variables in /etc/environment. then they are not user-scope any more.
I prefer the 1st option.
Create simple script
#!/bin/bash
source /home/user/.environment_variables
/home/user/eclipse_cpp/eclipse -Duser.name="My Name"
2.
Next put your all system variables in file /home/user/.environment_variables (any file you want)
My looks like:
export COCOS_ROOT=/home/user/Projects/edukoala
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
3.
Now you can delete your variables in .bashrc and put line
source /home/user/.environment_variables
Everything works fine :)
Well, this is already answered and the answer has been accepted. But this will also work for running your code using Eclipse. You can edit the Run Configurations and set the environment variable there. Then, Eclipse will pick up the variable from this setting while building.

How to specify a editor to open crontab file? "export EDITOR=vi" does not work

I'm using Red Hat Enterprise Linux 5, and I want to set the vim editor to edit the crontab file.
If I run echo $EDITOR, I get vim. But when I run crontab -e, I get different editor.
Very probable that your VISUAL environment variable is set to something else. Try:
export VISUAL=vi
To quote the man:
The -e option is used to edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables
Most often if you run crontab -e from X, you have VISUAL set; that's what is used. Try this:
VISUAL=vi crontab -e
It just worked for me :)
If the above methods don't work (as they didn't work on my Ubuntu 13.04 installation) try:
There are a number of alternative ways:
1) Run select-editor
select-editor
2) Manually edit the file: ~/.selected_editor specifying your preferred editor. With this option you can specify editor parameters.
# Generated by /usr/bin/select-editor
SELECTED_EDITOR="/usr/bin/emacs -nw"
3) You can specify on the fly on the commandline with:
env VISUAL="emacs -nw" crontab -e
You can use below command to open it in VIM editor.
export VISUAL=vim; crontab -e
Note: Please make sure VIM editor is installed on your server.
I think you might need to use the full path:
export EDITOR=/usr/bin/vim
export EDITOR=vim worked for me
It wasn't working for me. I run crontab with sudo, so I switched to root, did the above suggestions, and crontab would open in vim, but it still wouldn't from my user account. Finally I ran sudo select-editor from the user account and that did the trick.
This worked for me :
EDITOR="/usr/bin/vim"
export EDITOR
Add this to ~/.bash_profile or ~/.bashrc to enable this for current user.

Resources