Tag Info

Hot answers tagged

256

The simple stuff PATH=$PATH:~/opt/bin PATH=~/opt/bin:$PATH depending on whether you want to add ~/opt/bin at the end (to be searched after all other directories, in case there is a program by the same name in multiple directories) or at the beginning (to be searched before all other directories). You can add multiple entries at the same time. ...


59

You have to put the declaration in the initialization files of your shell: If you are using bash, ash, ksh or some other Bourne-style shell, you can add ABC="123"; export ABC in your .profile file (${HOME}/.profile). This is the default situation on most unix installations, and in particular on Debian. If your login shell is bash, you can use ...


49

Add cd /home/xxxx/Documents/Scripts/ if you want your job to run in that directory. There's no reason why cron would change to that particular directory. Cron runs your commands in your home directory. As for ssmtp, it might not be in your default PATH. Cron's default path is implementation-dependent, so check your man page, but in all likelihood ssmtp is ...


34

Either way works, but they don't do the same thing: the elements of PATHare checked left to right. In your first example, executables in ~/opt/bin will have precedence over those installed, for example, in /usr/bin, which may or may not be what you want. In particular, from a safety point of view, it is dangerous to add paths to the front, because if ...


31

You can use tr. $ tr ':' '\n' <<< "$PATH" /Users/arturo/.rvm/gems/ruby-1.9.3-p392/bin /Users/arturo/.rvm/gems/ruby-1.9.3-p392@global/bin /Users/arturo/.rvm/rubies/ruby-1.9.3-p392/bin ... You can also do this in some shells (tested in bash and zsh): echo -e ${PATH//:/\\n} In zsh, you can use the $path variable to see your path with spaces ...


29

You can always do: sudo env "PATH=$PATH" godi_console As a security measure on Debian, /etc/sudoers has the secure_path option set to a safe value.


24

Grepping around in /etc turned up a link that Googling did not. It turns out you can control this in the file /etc/fstab. Just add a line that says none / cygdrive binary 0 0 and the problem should be fixed. No more kludgey fixes in .bashrc, and no messed-up $PATH.


24

Note the output here: root:/usr/local/bin# siege bash: /usr/bin/siege: No such file or directory Bash maintains an internal hash of previously found executables in your path. In this case, it has details that at one time there was an executable at /usr/bin/siege, and reuses that path to avoid having to search again. You need to tell bash to manually ...


22

Having more entries in $PATH doesn't directly slow your startup, but it does slow each time you first run a particular command in a shell session (not every time you run the command, because bash maintains a cache). The slowdown is rarely perceptible unless you have a particularly slow filesystem (e.g. NFS, Samba or other network filesystem, or on Cygwin). ...


22

If you're the only user on the machine it's OK, as long as you know what's you're doing. The general concern is that by having your current directory in PATH, you cannot see commands as a constant list. If you need to run script/program from your current directory, you can always explicitly run it by prepending ./ to its name (you saying the system "I want ...


21

Probably to keep the kernel simpler. I don't think the kernel ever searches your path to find an executable. That's handled by the C library. #! processing is done in the kernel, which doesn't use the standard C library. Also, I don't think the kernel has a notion of what your path is. $PATH is an environment variable, and only processes have an ...


21

The risk is someone put a malicious executable in the directory that happen to be your current one. The worst case happen when: you are logged as root as the malicious command has unlimited damage power . is at the beginning of your PATH as standard commands can be overridden without you noticing it (typically an ls which could hide itself from the list). ...


21

Suppose that the new path that we want to add is: new=/opt/bin Then, using any POSIX shell, we can test to see if new is already in the path and add it if it isn't: case ":${PATH:=$new}:" in *:$new:*) ;; *) PATH="$new:$PATH" ;; esac Note the use of colons. Without the colons, we might think that, say, new=/bin was already in the path because ...


20

You cannot solve this through shebang directly, since shebang is purely static. What you could do is having some »least common multiplier« (from a shell perspective) in the shebang and re-execute your script with the right shell, if this LCM isn't zsh. In other words: Have your script executed by a shell found on all systems, test for a zsh-only feature ...


19

In zsh $PATH is tied (see typeset -T) to the $path array. You can force that array to have unique values with: typeset -U path And then, add the path with: path+=(~/foo) Without having to worry if it was there already. To add it at the front, do: path=(~/foo "$path[@]") or: path[1,0]=~/foo if ~/foo was already in $path that will move it to the ...


18

The shared library HOWTO explains most of the mechanisms involved, and the dynamic loader manual goes into more detail. Each unix variant has its own way, but most use the same executable format (ELF) and have similar dynamic linkers (derived from Solaris). Below I'll summarize the common behavior with a focus on Linux; check your system's manuals for the ...


15

I've seen people clean up duplicates from their PATH variable using awk and something like this: PATH=$(echo "$PATH" | awk -v RS=':' -v ORS=":" '!a[$1]++') You could try adding that to your own bashrc and make sure you source the other files somewhere before running that. And alternative would be to use this pathmearge utility. As for your speed ...


15

Not an interesting solution at all, but very portable: PATH=${PATH}:/my/path/1 PATH=${PATH}:/my/path/2 PATH=${PATH}:/my/path/3


14

On some systems, which -a shows all matches. If your shell is bash or zsh¹, you can use type instead: type foo shows the first match and type -a foo shows all matches. The three commands type, which and whence do mostly the same thing; they differ between shells and operating systems in availability, options, and what exactly they report. type is always ...


14

All the commands that a user might want to run are in the PATH. That's what it's for. This includes commands that you run directly, commands that other people run directly, and commands that you or other people run indirectly because they are invoked by other commands. This is not limited to commands run from a terminal: commands run from a GUI are also ...


14

In the most common cases, $0 will contain a path, absolute or relative to the script, so script_path=$(readlink -e -- "$0") (assuming there's a readlink command and it supports -e) generally is a good enough way to obtain the canonical absolute path to the script. $0 is assigned from the argument specifying the script as passed to the interpreter. For ...


13

What you are looking for is the PATH environmental variable. It tells the shell, where it needs to look for programs. You can see the current value of that variable using echo: echo "$PATH" Now... The best practice if you want use some new program is to install it using the package management program for your distribution. But in this case, I assume you ...


13

If you don't already have duplicates in the PATH and you only want to add directories if they are not already there, you can do it easily with the shell alone. for x in /path/to/add …; do case ":$PATH:" in *":$x:"*) :;; # already there *) PATH="$x:$PATH";; esac done And here's a shell snippet that removes duplicates from $PATH. It goes through ...


13

PATH is for specifying directories of executable programs. LD_LIBRARY_PATH is used to specify directories of libraries.


13

On linking You generally do not link /usr/local/* with /bin, but this is more of a historical practice. In general, there are a few "technical" reason why you cannot do what you're suggesting. Making links to executables in /bin can cause problems: Probably the biggest caveat would be if you're system is having packages managed by some sort of package ...


13

That's not the Bourne shell, or bash emulating the Bourne shell, that's the Almquist shell, in your case probably the Debian Almquist shell (a Linux fork by Debian of BSDs' sh itself based on the original Almquist shell). In the Almquist shell (the original one and the modern versions), % is used in PATH for extra features specific to ash. Quoting from the ...


12

You simply can't do this. There's no way¹ the make process can change its parent's environment (or its current directory, which you might be thinking of next). In fact, even less is happending than you think. Not all make implementations reflect the assignment to the make PATH variable in the environment; GNU make (found on Linux and other systems) does, ...


12

For bash use type -a assemble.sh


12

Use /etc/environment file for setting the environment variables. Then add the following line inside the /etc/environment file. ABC="123" Now the ABC variable will be accessible from all the user sessions. To test the variable output first refresh the environment variable using command source /etc/environment and run echo $ABC.


12

You have to use source or eval or to spawn a new shell. When you run a shell script a new child shell is spawned. This child shell will execute the script commands. The father shell environment will remain untouched by anything happens in the child shell. There are a lot of different techniques to manage this situation: Prepare a file sourcefile containg ...



Only top voted, non community-wiki answers of a minimum length are eligible