Echo $JAVA_HOME returns empty despite being present in .bashrc, .bash_profile, .profile files - linux

I've added the following line in all 3 files:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
If I do, echo $JAVA_HOME, I get empty line as output.
If I do source .bash_profile and then do echo $JAVA_HOME, I get the output correctly.
If I close the terminal application and re-open the terminal app again, echo $JAVA_HOMEshows empty again. Isn't .profile or .bash_profile supposed to load it to bash when I reopen? I added it to all 3 files to be sure. But it just doesn't seem to work
Note: I'm using Zsh on Mac. Does this have anything to do with what I'm facing?

Thanks #JoachimIsaksson for the solution in the comments. I had to move stuff to .zprofile for zshell on Mac and it worked.

Related

I set .bashrc but my promt looks still the same

i'm quite new with linux and I want to tweak my terminal prompt. The default is user#user - Thinkpad- T420 ~$. That pretty annoying long.
I searched google and I tried my best but it didn't show any difference.
What i have done:
echo $PS1
\[\e]0;\u#\h \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u#\h\[\033[00m\] \[\033[01;34m\]\w \$\[\033[00m\]
locate bashrc
/etc/bash.bashrc
/etc/skel/#.bashrc#
/etc/skel/.bashrc
/etc/skel/.bashrc~
/usr/share/base-files/dot.bashrc
/usr/share/doc/adduser/examples/adduser.local.conf.examples/bash.bashrc
/usr/share/doc/adduser/examples/adduser.local.conf.examples/skel/dot.bashrc
sudo -s Atom /directory
I changed in all files PS1="...." to PS1="hallo". Terminal prompt shows no difference.
Linux Kernel
Mint
4.8.0-53-generic
greetings ! B
source ~/.bashrc
Your terminal only reads the .bashrc on opening, or when you explicitly source it.
I fixed it by editing the .bashrc file in my /home/myusername directory. Don't edit the files here /src/skel

MSYS2 on Win7 prints "Can't find file" after every command?

I just installed MSYS2 on my Windows 7 VM and the only stuff I've really done so far was that I modified my ~/.bashrc file by adding a few lines.
The only stuff I added to the file was a few alias cmds, an export cmd, and I modified the PS1 variable. See below:
alias ll='ls -l'
alias la='ls -A'
alias cls='clear'
export PATH="$PATH:/home/Matt/bin"
PS1=$(print '\033]0;${PWD}\n\033[32m${USER}#${HOSTNAME}:\033[33m${PWD/${HOME}/\~}>\033[0m ')
Other then that stuff above, that's all I've really done. So after making the changes to ~/.bashrc I exited from MSYS2's command prompt and then restarted MSYS2 to make the .bashrc changes go into effect. I know I could have just re-sourced the file but I just quickly exited and restarted instead...
Then, after I restarted MSYS2 this printed as the first line in the terminal --> "Can't find file" and then after everytime I hit enter at the cmd prompt it prints "Can't find file" just before the next prompt prints to the screen, like below:
Terminal shows this when I start-up MSYS2:
--------------------------------------------------------------------
Can't find file
Matt#My-Win7VM:~> ls -l
total 0
drwxr-xr-x 1 My-Win7VM+Matt My-Win7VM+None 0 Jun 3 12:01 bin
Can't find file
Matt#My-Win7VM:~>
Can't find file
Matt#My-Win7VM:~>
Can't find file
Matt#My-Win7VM:~>
--------------------------------------------------------------------
Any ideas what file it could be talking about that it can't seem to find..?
Any thoughts or suggestions would be greatly appreciated.
Thanks in Advance,
Matt
Ok I think I found the problem.
I ran the env command, and the PS1 environment variable was showing this
PS1=Can't find file \033]0;${PWD}\n\033[1;31m${USER}#${HOSTNAME}:\033[1;34m${PWD/${HOME}/\~}>\033[0m
So I removed the export PS1=${print ...} line from my ~/.bashrc file to just a double quoted variable assignment, instead of using the print command.
Because it looks like the print command is trying to be run from "/c/Windows/system32/print" and if you pass it a string you can see the error that was showing:
$ which print
/c/Windows/system32/print
$ print "Hello World"
Can't find file Hello World
So as you can see, that print command is expecting a filename, and not a string. So switching it to just an assignment statement like below, fixed the error:
export PS1="\033[1;31m${USER}#${HOSTNAME}:\033[1;34m${PWD/${HOME}/\~}>\033[0m "
Now everything seems ok.
EDIT:
Ran into new problem where the directory in the prompt wasn't changing when I switched dirs... Found out I was using the wrong method. So I found the PS1 switches and now it's all better this time:
PS1="\033[1;31m\u#\h:\033[0m\033[1;34m\w>\033[0m "
-Matt
Looks like you've copied your $PS1 from /etc/profile
Try the $PS1 variable from /etc/bash.bashrc instead:
# Set a default prompt of: user#host, MSYSTEM variable, and current_directory
PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u#\h \[\e[35m\]$MSYSTEM\[\e[0m\] \[\e[33m\]\w\[\e[0m\]\n\$ '

Add a command for bash script to terminal

I have studio.sh file in my android-studio/bin folder, which I would like to use as a command in bash (like launching any other normal application).
I read somewhere that adding this line to ~/.profile should work,
export PATH=$PATH:/home/goel/android-studio/bin
But it doesn't work. Whats the correct process?
Add the script folder name to PATH environment variable in ~/bash.rc file
and you can also create alias for you script in ~/bash.rc
and source the /etc/bash.bashrc file, now you can issue your script or alias name in any terminal. Hope this helps.
If you change your PATH in a .profile, you still have to make the shell read the .profile. Starting a new terminal is sometimes not enough (some terminals don't read the .profile), in which case you have to log out and back in.
Is studio.sh executable? Have you tried ./studio.sh inside its containing folder to check whether it runs at all?

$HOME/bin in path on Linux Mint 14

I'd like to amend my user's path in Linux Mint 14 Cinnamon to include $HOME/bin in my user's $PATH.
Warning: simply adding to .profile does not seem to work, even though other commands in .profile are called correctly and even though it works when calling source .profile explicitly.
What are my alternatives?
It turns out the right file to do the edit into is .bashrc, not .profile. .profile will call .bashrc at its beginning.
Add to .bashrc:
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
export PATH="$HOME/bin:$PATH"
fi
Putting the text in ~/.bashrc worked for me. It's just so delightful when the documentation lies to me like right there in the .profile file.
Modifying environment variables (like PATH) in and rc script is a very bad
idea.
1: it's executed for all scripts , not just from command line
2: as you get deeper is shells , you'll get more and more prepended paths
.profile or .bash_profile is correct , only done once at login ... seems there is a bug here in Cinnamon
I'm also seeking and answer as to how to set my $PATH in Cinnamon, as the solution (.profile) which has more fine for te past 30 years is not working here. (nor does .xsessionrc BTW)

Defining aliases in Cygwin under Windows

I am trying to define some aliases in cygwin, but with no success. I am doing so like this at the end of the .bashrc file.
alias foo='pwd'
I have tried to add this line in a .bashrc file in both inside the home folder of cygwin and in the home folder for the Windows user I am on C:\Users\Nuno\. In both cases I have just appended this line to a copy of the /etc/skel/.bashrc file. In either cases, it didn't work.
I had this working before. I had to reinstall Cygwin and ever since it never worked properly again. I have removed all files (or at least think so, when doing the reinstallation). I have also noticed that in the first install (when it was working) cygwin already was creating .bash files in the home folder. Now, it doesn't.
I am on a machine running Windows 7.
EDIT: My cygwin home folder is set to the Windows home folder C:\Users\Nuno\. I have placed what I think is a valid .bashrc file there, but it still doesn't work.
Thanks in advance.
As me_and already explained what's going on I just want to add a workaround should you for whatever reason not be able or willing to remove Windows' HOME environment variable.
Normally the shortcut for Cygwin executes
C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -
Instead you can create a batchfile with the following content and start that:
#echo off
set HOME=
start C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -
That will start a a Cygwin windows whose home directory settings are not overridden by a Windows environment variable.
Your .bashrc file will be loaded from wherever Cygwin Bash thinks your home directory is when it starts. You've mentioned in your edit that you've changed your home directory, but not how, so it's possible you've made a mistake there.
Cygwin will load your home directory from one of two places, and if they differ it can cause problems:
The HOME environment variable. This will be picked up from however you launch Cygwin, so normally from Windows itself. You can see what environment variables you have defined by pressing Win+Pause, going to "Advanced system settings", "Environment Variables…". If "HOME" is in either "User variables" or "System variables", delete it – it's unnecessary and only causes problems.
Cygwin's /etc/passwd file (normally C:\Cygwin\etc\passwd from Windows). This will have a number of lines containing details of each user on the system; the seventh : separated field is the home directory. You can tell which user it's looking at by running whoami from a Cygwin bash shell.
If whoami reports nunos, you should have a line in Cygwin's /etc/passwd that looks something like the following:
nunos:unused:1001:513:U-System\nunos:S-1-2-34-567890-123456-7890123-1001:/home/nunos:/bin/bash
It's that /home/nunos that's important; if it's something different you should probably reset it to that, at which point you want to use the .bashrc in Cygwin's /home/nunos/.
You should also be very wary of directories that contain spaces for this. C:\Users\nunos should be fine, but beware in particular C:\Documents and Settings\nunos, which just won't work with Cygwin.
I had the same issue, where the aliases added to ~/.bashrc didn't work.
It seems that, for some reason, the ~/.bashrc was not executed when launching the console.
I stumbled upon a response that fixes the issues
So, you need to create a .bash_profile file. This one seems to be the default script, and put this code in it, to ensure that the .bashrc is executed.
# ~/.bash_profile: executed by bash for login shells.
if [ -e /etc/bash.bashrc ] ; then
source /etc/bash.bashrc
fi
if [ -e ~/.bashrc ] ; then
source ~/.bashrc
fi
That works for me, just make sure that .bash_profile is executable. (chmod +x ~/.bash_profile)
Here's a really quick and dirty way to do it, but it works fine for most things!
Let's say you want to always run 'ls --color' instead of just 'ls'. Instead of messing around with .bashrc stuff, you can create a simple .bat file that essentially bootlegs the original ls command.
Here's what I did:
cd /bin
echo ls2.exe %* --color > lsNew.bat
mv ls.exe ls2.exe
mv lsNew.bat ls.bat
So now, whenever you type in ls from CMD, you actually are calling ls.bat, which in turn calls ls2.exe --color, the original ls command with the --color flag, along with the rest of the arguments, which are nicely passed through %*.
I had the same problem, but I was using ConEmu to run my console. I had to go into settings and change the settings from this :
set CHERE_INVOKING=1 & %ConEmuDrive%\Programs\Cygwin\bin\sh.exe --login -i -new_console:C:"%ConEmuDrive%\Programs\Cygwin\Cygwin.ico"
to this:
set HOME= & set CHERE_INVOKING=1 &
%ConEmuDrive%\Programs\Cygwin\bin\bash.exe --login -i
-new_console:C:"%ConEmuDrive%\Programs\Cygwin\Cygwin.ico"
Then it would work correctly.
It works as explained from cygwin:
Create a file ".profile" in your windows home dir. This will load every time when you start cygwin.
You can edit the file with your alias or you can source the .bashrc.
If you'll source, insert "source .bashrc" and save .bashrc also in your windows home dir.
Now you can start editing the .bashrc.
This is working for me On windows 10 with Cygwin64. Don't worry "kubectl" is just the program that I want to run when I type "k". restart Cygwin terminal after the change.
Smith#NB-Smith-3 ~ echo "alias k=C:/Users/Smith/kube/kubectl" >> $HOME/.bash_profile
changes this file
C:\cygwin64\home\Smith.bash_profile
I had same problem is why the path not is correct, the path correct is: D:\C++\cygwin\home\USER_WINDOWS.bash_profile

Resources