Hi I'm trying to add a directory to the path directly on my vagrant provision but something didn't work as expected. I'm using this line
echo PATH=\""$"PATH:/opt/paraviewopenfoam410/bin\" >> /home/vagrant/.profile
If I use it inside a terminal works as expected adding at the of the .profile the following line
PATH="$PATH:/opt/paraviewopenfoam410/bin"
But when using in vagrant provision the result is:
PATH="PATH:/opt/paraviewopenfoam410/bin"
Missing the $ symbol and breaking the PATH variable
When using the " it will resolve variable so no matter how you put it and escape it, vagrant will resolve the $PATH variable and output the result in your .profile
If you just want to have plain text $PATH you just need to do with '
echo PATH=\'$PATH:/opt/paraviewopenfoam410/bin\' >> /home/vagrant/.profile
will work just fine
Related
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.
I want to add the path to pycharm.sh to PATH (Pycharm community Edition 5.0.2), which is stored in /opt/pycharm-community-5.0.2/bin. At first I added the following line to /etc/environment, which was an empty file before:
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/opt/pycharm-community-5.0.2/bin"
Afterward I tried to start Pycharm via terminal, without success:
$ pycharm
bash: pycharm: command not found.
My next step was to change the value of PATH inside the first if statement in /etc/profile as follows:
if [ "`id -u`" -eq 0 ]; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/pycharm-community-5.0.2/bin"
else
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/opt/pycharm-community-5.0.2/bin"
fi
export PATH
I restarted the system after each step, but I still the receive the same error message.
Is there another way to permanently set the variable? What am I doing wrong?
Your executable filename is pycharm.sh, not pycharm. Try typing that instead.
You could also try which pycharm.sh, which attempts to locate given command using PATH environment variable, to see that your configuration works.
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\$ '
I didn't write the vagrant file - it was made by a colleague of mine, and I'm not overly familiar with writing them, but based on what they look like, I can understand what it's doing to an extent. I'm running Windows and a precise32 virtualbox, and emulating some sort of Linux system.
Basically what's happening is the vagrant file executes bootstrap.sh, which contains the following line:
cat /vagrant/support/bash-template.dat >> /home/vagrant/.bashrc
support/bash-template.dat contains
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
When I check .bashrc after ssh'ing into vagrant, it has this line at the bottom.
If I do
> echo $JAVA_HOME
I get
/usr/lib/jvm/java-7-openjdk-i386
But if I do
>cd $JAVA_HOME
I get
: No file or directorya-7-openjdk-i386
What's going on here? It just mashes the latter half of the variable with the error message.
And the directory exists! If I go from root, I can do
~> cd /usr/lib/jvm/java-7-openjdk-i386
And it brings me to the java home place.
I can reexport variables in the shell, and they work, but it would be very helpful to be able to do it from .bashrc so I don't have to reexport all 15 variables every single time I log on.
Thanks in advance for any help.
You can use the dos2unix util to fix your line ending mismatch.
I have created a simple script:
echo "the path of the current directory is `pwd`"
and saved it by the name pathinfo
then i have created a bin directory at my home page with path as
/home/vpnsadmin/bin
and copied my script(pathinfo) to that bin directory.
Now i want run this script as a command but it is showing error
-bash: /usr/bin/test2: No such file or directory
but if copy my script(pathinfo) to "/usr/bin/" then it runs as a command.
the PATH environment variable is set as-
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/home/vpnsadmin/bin
My question is why does the shell not run it as a command when it is present in /home/vpnsadmin/bin.
or else
why does it only check for the binary at /usr/bin and not at /home/vpnsadmin/bin or at /bin
The shell that is to execute your command needs to have the correct PATH variable set at the time of execution and, depending on shell, might need to have created its own internal (hash)map of the available commands.
Assuming you are using bash, try the following with your script saved in /usr/bin:
$ PATH=/ test2
$ PATH=/usr/bin test2
In the first case you should get an expected "not found" error, in the second it should work. The third test to perform is left as an exercise...
And I have to say that the supplied error message looks a bit odd if you actually tried to do
$ test2
and not
$ /usr/bin/test2
before copying the command to /usr/bin.
Edit:
Also, avoid naming your scripts test, in any way shape or form. This causes so much confusion for beginners.
Hint:
man test
Did you have the path to bash at the top of your script and did you use backticks around pwd?
#!/bin/bash
echo "the path of the current directory is `pwd`"
Did you make the file executable?
chmod +x pathinfo
There is another script pathinfo somewhere in your path which contains a call to /usr/bin/test2
Try whereis pathinfo to see how many there are and which pathinfo to see which one your shell currently prefers.