You are not logged in.
Pages: 1
i have a directory ~/scripts
does anyone know how to add this to my PATH so that i can use tab completion?
Offline
http://tldp.org/LDP/Bash-Beginners-Guid … 03_02.html
$PATH is a global variable. You can assign a global variable like
export variablename="value"
Without the 'export' it would be a local variable, visible only in the current shell instance. Because you want to pass this variable to programs or scripts you run, you make it global.
To make this permanent/default put the statement in your ~/.bashrc (or your shells config if you're using something else than bash), so it will execute as soon as you start your shell. For example a line from my config:
[[ -d $HOME/.bin ]] && export PATH=$HOME/.bin:$PATH
As you can see with `echo $PATH`, the paths in $PATH are separated by a ':'. So I prepend the value of $HOME (your homefolder) and a ':' to the current value of $PATH, and assign it to $PATH.
For lack of better words: chair, never, toothbrush, really. Ohw, and fish!
Offline
i read this somewhere as the "right" way to do it. using this approach only adds the new directory/ies if they aren't already present so you don't eff up your PATH if you re-source .bashrc again later.
# what to add to path
NPATH="$HOME/.bin"
# add it only if required
case ":${PATH}:" in
*:${NPATH}:*) ;;
*) PATH=${PATH}:$NPATH ;;
esac
export PATH
you could easily add the check if the directory exists first. you could also reorder PATH and NPATH depending on which should take precedence.
//github/
Offline
@brisbin33
Yup - that is a very wise suggestion ...
Personally I have something I call 'brush_path' where I can prepend/append directories to the original $PATH (directories with a leading '-' are prepended and a '+' appends them - it goes something like this:
#!/bin/sh
# process arguments - only those starting with '-' or '+' are honoured ...
preps=""
apps=""
for a in $*; do
case $a in
-*) preps="$preps ${a#-}" ;;
+*) apps="$apps ${a#+}" ;;
esac
done
# get the complete path
dirs="`echo $preps $PATH $apps | tr ':' ' '`"
# clean it all up ...
newpath=""
for d in $dirs; do
ok=yes
for p in $newpath; do
test "$d" = "$p" && { ok=no; break; }
done
test "$ok" = yes && newpath="$newpath $d"
done
echo $newpath | tr ' ' ':'
Now - as one of the last things I do in .bashrc is:
test -f /usr/local/bin/brush_path && export PATH="`sh /usr/local/bin/brush_path -~/bin -/usr/local/bin"
Last edited by perbh (2009-11-13 06:18:29)
Offline
Looks complicated....
> head -1 .bashrc
PATH=~/bin:$PATH
No need for checking given you know that your scripts directory is present...
Online
In my config.fish:
# fish does not allow setting nonexistant dir to PATH
# Arch default includes nonexistant directories
# ~ echo $PATH
# /bin /usr/bin /sbin /usr/sbin /usr/bin/perlbin/site /usr/bin/perlbin/vendor /usr/bin/perlbin/core
# We'll set the PATH manually for now.
set -l myPATH $PATH
for i in $myPATH
if test -d $i
if not contains $i $newPATH
set newPATH $newPATH $i
end
end
end
set PATH $newPATH
set -e newPATH
Otherwise I end up with no PATH at all when I try to add anything.
aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies
Offline
No need for checking given you know that your scripts directory is present...
True... But I share this config between multiple computers:P
For lack of better words: chair, never, toothbrush, really. Ohw, and fish!
Offline
Pages: 1