How do I add a location to my path in Unix?

12

1

I am using a default installation of FreeBSD, with the C shell (csh).

Suppose I have a command I can run by executing this: /sbin/abc, but cannot run by executing abc. How can I set certain path or something that make abc runnable everywhere?

Andy Leman

Posted 2010-12-22T07:00:24.480

Reputation: 305

By the way, for zsh syntax, see Adding a new entry to the PATH variable in ZSH

– Basil Bourque – 2019-07-25T18:35:18.013

http://wiki.centos.org/TipsAndTricks/BecomingRoot – Ignacio Vazquez-Abrams – 2010-12-22T07:01:50.383

what shell do you use? setting your path is done slightly differently in bash, csh, sh, tcsh, etc. You can generally run echo $SHELL to find out which shell you're using. – Tim – 2010-12-22T07:08:58.747

Answers

13

Aha, FreeBSD. That's tcsh, I believe.

So:

set path=(/sbin $path)

DigitalRoss

Posted 2010-12-22T07:00:24.480

Reputation: 2 968

7

bash & zsh syntax:

export PATH=${PATH}:/sbin

sh syntax (two separate commands):

PATH=${PATH}:/sbin
export PATH

csh and tcsh:

setenv PATH "${PATH}:/sbin"
set path=($path /sbin)

This will append /sbin to your path, so when you type abc, the shell will also look in /sbin for it. You can also add the command to your ~/.bashrc file (or ~/.cshrc, ~/.tcshrc, ~/.profile, ~/.login—depending on which shell you use).

Tim

Posted 2010-12-22T07:00:24.480

Reputation: 422

I got "export command not found" I am using Freebsd 8.1 – None – 2010-12-22T07:08:35.773

Let me know which shell you're using, and I'll update the syntax. – Tim – 2010-12-22T07:09:48.000

I have no idea which shell I am using. It's default FreeBSD, i didn't change anything... – None – 2010-12-22T07:11:31.407

2type echo $SHELL to find out which shell you're using, and run the appropriate commands (I'm guessing tcsh/csh since you don't have export). I've updated this answer with syntax for all three. – Tim – 2010-12-22T07:12:44.440

/bin/csh [ word padding...................] – None – 2010-12-22T07:15:46.163

This will work but csh and tcsh were intended to use the native wordlist variables and then PATH is generated automatically. Since the setenv command will only DTRT with PATH, it would be better for a tcsh user to learn the syntax that will work with all of his variables. The command he should be using is in my answer below. – DigitalRoss – 2010-12-22T07:20:55.880

@DigitalRoss, I forgot about that quirk of csh -- I mostly used bash. Anyway, I updated the post. @Andy, if abc is something you use a lot, you may want to put the command into your ~/.tcshrc file, so you don't have to type it everytime you log in. – Tim – 2010-12-22T07:34:37.380