Hi Linux noob here,
I wanted to link the LLC.exe with one of the shared libraries , the thing what I do is in order to make the llc -c to work I have to link them like these
PATH="/usr/local/bin:/usr/bin:/bin:/opt/noob/bin"
LD_LIBRARY_PATH="/opt/noob/lib"
export PATH LD_LIBRARY_PATH
If I give these commands it works , Now I want to automate this so I wrote a this in a .sh (bash script ) file and called it in rc.local file but it does-not work, also I tried to put the above lines in the rc.local still it "llc" doesnt work. Please tell me what I am doing wrong.
I tried giving
echo $PATH
/usr/local/bin:/usr/bin:/bin:/opt/noob/bin
is the output
But when I give
echo $LD_LIBRARY_PATH
It gives me nothing. I just want to execute this lines on startup. The huddle is I dont want to edit anything in /etc/ directory. PLEASE HELP ME !!
The first snippet shows that you setting the PATH and LD_LIBRARY_PATH environment variables. PATH is used by the shell to binaries, and LD_LIBRARY_PATH to find libraries when you execute a program. None of those commands are linking anything.
$echo PATH will try to deference the echo variable. If that $ is your prompt then it will print "PATH" not the value of the PATH variable.
This is how you echo variables:
echo $PATH
echo $LD_LIBRARY_PATH
Related
I have a few questions on this $PATH in Linux.
I know it tells the shell which directories to search for executable files, so:
What does it mean an environmental variable?
How to change its path? and is it recommended to change it?
IF i change it what are the consequences?
To get your path current $PATH variable type in:
echo $PATH
It tells your shell where to look for binaries.
Yes, you can change it - for example add to the $PATH folder with your custom scripts.
So: if your scripts are in /usr/local/myscripts to execute them you will have to type in a full path to the script: /usr/local/myscripts/myscript.sh
After changing your $PATH variable you can just type in myscript.sh to execute script.
Here is an example of $PATH from RHEL:
/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/user/bin
To change your $PATH you have to either edit ~/.profile (or ~/.bash_profile) for user or global $PATH setting in /etc/profile.
One of the consequences of having inaccurate $PATH variables is that shell will not be able to find and execute programs without a full $PATH.
Firstly, you are correct in your statement of what $PATH does. If you were to break it somehow (as per your third point), you will have to manually type in /usr/bin/xyz if you want to run a program in /usr/bin from the terminal. Depending on how individual programs work, this might break some programs that invoke other ones, as they will expect to just be able to run ls or something.
So if you were to play around with $PATH, I would suggest saving it somewhere first. Use the command line instruction
echo $PATH > someRandomFile.txt
to save it in someRandomFile.txt
You can change $PATH using the export command. So
export PATH=someNewPath
HOWEVER, this will completely replace $PATH with someNewPath. Since items in path are separated by a ":", you can add items to it (best not to remove, see above) by executing
export PATH=$PATH:newPath
The fact that it is an environmental variable means that programs can find out its value, ie it is something that is set about the environment that the program is running in. Other environmental variables include things like the current directory and the address of the current proxy.
this is simple and i do like this way.
Open the linux bash shell and print the environment variables:
printenv
I copy "PATH" variable to a text editor and edit as I want. Then update the PATH like this
export PATH= /variable dir list/
It Works.
or if you want to add an single variable use this command.
export PATH = $PATH:/variable_dir_path/
This will extends the PATH with your new directory path.
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
I had something weird happen on my computer.
I had gperf installed under /usr/local/bin.
As related to questionI asked here I had a perl script running on my computer which contain the line system() on gperf with flags something look like
perl file:
system("gperf ...") == 0 || die "calling gperf failed: $?";
However no matter how hard I try the gperf will not run and out put the failed message
to debug I tried something like
system("echo \$PATH") == 0 || die "calling gperf failed: $?";
and found that it does not contain /usr/local/bin/ where i installed my gperf but only look in usr/bin where it was not installed
So the $PATH is wrong...
So I googled around and saw system() is same as calling /bin/sh inside a file so i tried /bin/sh and echo $PATH which found that it contain /usr/local/bin/ to my disbelieve.
So my question is where is the $PATH for a system() declared? why is it different then the one inside a Bourne shell ?
The PATH used by commands launched via system is the same as the one in the perl script, accessible through $ENV{PATH}. It's the PATH that the perl script inherits from the program that called it, unless you changed it in the script.
What's biting you is probably that you set up your PATH in the wrong configuration file. Define it in ~/.profile, /etc/profile or other system-wide file, not in a shell configuration file such as .bashrc. See this question for some general information.
If you want to set the path manually inside the perl script, you can use something like
$ENV{PATH} = "/usr/local/bin:$ENV{PATH}" unless ":$ENV{PATH}:" =~ m~:/usr/local/bin:~;
but this is probably a bad idea: in most cases, your script should not modify the path chosen by the user who runs that script.
If you're having trouble finding the right place to set PATH on your system after reading the question I linked to and the questions linked in my answer there, ask on Unix & Linux and be sure to state the details of your operating system (distribution, version, etc.) and how you log in (this is a user question, not a programming question).
On a linux system using BASH as the shell, the PATH is set at login time from the user's .bash_profile file in their home directory. You can append the /usr/local/bin directory with a line like this at the end of the file:
PATH=$PATH:/usr/local/bin
The other (probably more reliable) way to fix it is to use the absolute path in your system call, like this:
system("/usr/local/bin/gperf")
I am trying to add a folder to the PATH in linux. I want to automate it through a script.
This is the script I have written:
#!/bin/sh
echo "Setting PATH..."
echo "export PATH=$PATH:/opt/mysoftware/scripts/client" >> ~/.bashrc
. ~/.bashrc
Even after executing the script, PATH is not getting updated.
But I can see that bashrc file has been updated.
When I logout and login, PATH is updated.
What might be the problem?
You're running the script in a child shell. Try sourcing it:
source script.sh
If you want this in your .bashrc, delete the script. You're done now. ;-)
The alternative is to put this in a function. I used to have two functions,
use() and forget() in my ksh environment that did exactly that.
use /opt/python would be equivalent to PATH=/opt/python/bin:$PATH, once.
A second run would do nothing. Even use python would look in a couple of
locations for /{usr,opt}/python/{bin,sbin} and insert the first match to PATH.
Conversely, forget python would remove /opt/python/bin: from the PATH again.
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.