LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Why "-bash: ifconfig : command not found" when typing "$ifconfig" (https://www.linuxquestions.org/questions/linux-server-73/why-bash-ifconfig-command-not-found-when-typing-%24ifconfig-687928/)

dangdtvn 12-03-2008 12:54 AM

Why "-bash: ifconfig : command not found" when typing "$ifconfig"
 
i typed "$ifconfig" in the redhat 4. And it returned above error.other users, it does not matter at all. So someone can tell me the reason.


thanks!

SqdnGuns 12-03-2008 01:09 AM

Run as root, the command is "ifconfig"

dangdtvn 12-03-2008 04:23 AM

Any reason else?

repo 12-03-2008 04:41 AM

Because ifconfig is locate in /sbin
sbin is not in the path from regular users, only in path from root.
you can execute the command by typing /sbin/ifconfig

colucix 12-03-2008 04:43 AM

Well, this happens only if you have a variable ifconfig whose value is ifconfig and you're not root, that is
Code:

$ ifconfig=ifconfig
$ $ifconfig
-bash: ifconfig: command not found

but I see no reason to launch a command as $variable, unless you have a script which dynamically set the name of the command and store it in a shell variable. Moreover, as already stated by SqdnGuns above, you have to be root to run ifconfig otherwise - as a regular user - it is not in your PATH.

Actually, you can run the ifconfig command as a regular user if you launch it with its absolute path:
Code:

$ /sbin/ifconfig
but only to display the ethernet interface settings, not to modify the settings themselves - for which you have to acquire root privileges. Please note that in my examples above the greyed $ sign is the command prompt.

dangdtvn 12-04-2008 12:10 AM

Thank everybody
 
I understood more about this issue!

thanks!

sakibmas 09-20-2013 04:05 AM

Quote:

Originally Posted by repo (Post 3362806)
Because ifconfig is locate in /sbin
sbin is not in the path from regular users, only in path from root.
you can execute the command by typing /sbin/ifconfig

sudo export PATH=/sbin:$PATH

Firerat 09-20-2013 04:16 AM

Quote:

Originally Posted by sakibmas (Post 5031236)
sudo export PATH=/sbin:$PATH

no need for sudo
in fact, it won't work, since export is a bash builtin command

sakibmas 09-20-2013 05:51 AM

Quote:

Originally Posted by Firerat (Post 5031238)
no need for sudo
in fact, it won't work, since export is a bash builtin command


add this line in ~/bashrc file
export PATH=$PATH:/sbin

Firerat 09-20-2013 06:01 AM

~/.bashrc

but better to have it in ~/.profile
that way it is also available to other shells ( ksh, ash , csh and so on )


All times are GMT -5. The time now is 05:52 PM.