LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   About adding PATH directories and maping in vim (https://www.linuxquestions.org/questions/linux-newbie-8/about-adding-path-directories-and-maping-in-vim-509757/)

SW-ANIKY 12-12-2006 12:09 PM

About adding PATH directories and maping in vim
 
I have 2 small problems, i have the sw11.0.
The 1st one, i want that my root directory be in the PATH, i add it, but i cant execute my C executable files directly.
I added the following directories into the PATH, /~, /root. It is wrong?

The 2nd is a vim remaping problem, i want to remap the f1 key to work like esc, i cant do it,i can remap esc to work calling help, but my f1 key dont work like esc. (i have the esc key a little far away and it force my hand to move out of the writing keys).

THANKs.

acid_kewpie 12-12-2006 12:38 PM

well your root directory should *NOT* be in your path. it's a really bad idea. if you wish to run your own compiled software, then you should put it in somewhere like /usr/local/bin/, or just run it with a relative or absolute path. now if you deicide to go against stnadard conventions then "/~" doesn't really make sense, it's invalid, but /root should be fine, so you've presumably got a syntax problem in the way you are defining it, or you are applying incorrectly somehow.

SW-ANIKY 12-12-2006 02:16 PM

I put in the cmdln
export PATH=$PATH:root/java
it work. But i want it to be executed in the boot.
I put the same line in etc/rc.d/rc.local
and it isnt working, what must put instead?

acid_kewpie, a folder into the root directory is also unrecomended?
why i mustnt put the root directory into the path?

THANKS

acid_kewpie 12-12-2006 02:20 PM

/root is where the system administrator puts all sorts of little bits of information and such, it's just not an organizd place to pur exectuables in the long term.

but if you must, edit your own personal /root/.bashrc file and add it there, e.g. "export PATH=$PATH:/root"

SW-ANIKY 12-12-2006 07:07 PM

I do it, but it dosnt work. The .bashrc file was empty, and i dont know if it already exist before i open it with: vim .bashrc
I put the ls command, and i cant see the file. Why i cant see it?, it is ocult?.

acid_kewpie 12-13-2006 02:07 AM

a file that starts with a . is hidden. add the -a flag in ls and you'll see them. your bashrc really will always exist, unless you don't use bash or have a distro i've never seen before. you can also try ~/.profile too, which is largely shell agnostic.

nx5000 12-13-2006 05:59 AM

.bashrc is not executed on login shells.
And bash_profile is not executed if bash is called by #!/bin/sh.

So the best, IMO, would be to put this at end of /etc/profile:

Code:

if [ "`id -u`" -eq 0 ]; then
  PATH=$PATH:/root/java
fi
export PATH


jschiwal 12-13-2006 06:50 AM

It is common to have a ~/bin/ personal bin directory to execute your own scripts and personal program files. Commands you install from a tarball probably should be installed in /usr/bin/ or /usr/local/bin/.
You can add the line "export PATH=$PATH:$HOME/bin" to your ~/.profile file. The .profile is run when you login, so you will need to run it manually "./.profile" if you haven't logged out. Also, the ~/.bashrc file is run every time a new subshell is run, so if you used ~/.bashrc instead, your added paths will be added twice.

acid_kewpie 12-13-2006 08:34 AM

Quote:

Originally Posted by nx5000
.bashrc is not executed on login shells.
And bash_profile is not executed if bash is called by #!/bin/sh.

So the best, IMO, would be to put this at end of /etc/profile:

Code:

if [ "`id -u`" -eq 0 ]; then
  PATH=$PATH:/root/java
fi
export PATH


what do you mean not exectued on login shells? of course it is... and why would you want a single uid specific test to be run on a system wide script? can't see the logic there at all

nx5000 12-13-2006 08:52 AM

Sorry, its not, see bash manual page:
http://www.die.net/doc/linux/man/man...tml#invocation
I will add that if /etc/profile is executed then ~/.profile is not executed.

This is what comes when you install debian, it looks very similar:

Code:

root@debian# more /etc/profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "`id -u`" -eq 0 ]; then
  PATH="/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/
usr/bin/X11"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games"
fi

if [ "$PS1" ]; then
  if [ "$BASH" ]; then
    PS1='\u@\h:\w\$ '
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

export PATH

umask 077

So the logic seems to be the same..

acid_kewpie 12-13-2006 09:26 AM

yes, it calls ~/.bash_profile which as a standard for years and years has sourced ~/.bashrc if it's found. not sure why it really goes round the houses like that, but it's the way i've always known it.

wmakowski 12-13-2006 11:51 AM

Not that I would recommend this, but to map your F1 key in vi to be Esc you'll need to edit a file called .exrc in your home directory. Once in there enter the following.
Code:

:map! #1 ^[
Note: the ^[ is made using the keys Cntl+V Esc. To be more clear you hold down the control key and V at the same time, let go, then hit the Esc key. Using the map with ! means it will work while in insert mode, #1 is F1, and ^[ is how it interprets the escape key.

You may still encounter a problem if you are using a terminal window in Gnome(I don't have KDE, so don't know). The Gnome terminal will capture your F1 and bring up help before it gets to vi. This can be overridden. On the Terminal screen menu go to Edit, then Keyboard Shortcuts. At the bottom of the list you'll see F1 listed as the shortcut key for help.

Now, having said all that, it is not a good practice to use F1. F1 has been the standard help key on applications since function keys were first invented.

For the $PATH question I would not put an entry in /etc/profile since that is system wide. It would be better to put it in /root/.bash_profile. That is always executed during login and typically where your environment is set. Also since SW-ANIKY is talking C executables and not java, /root/bin would be a more appropriate directory. A few people have said something similar to this already, but here is the entry I would use.
Code:

export PATH=$PATH:$HOME/bin
-or-
PATH=$PATH:$HOME/bin
export PATH

While most distributions include 'if' logic to execute .bashrc in their .bash_profile, it is possible that is missing in SW-ANIKY's .bash_profile and that is why it's not working. A more probable explanation is that he did not logout and log back in or execute the .bashrc using the command source ~/.bashrc.

Some may disagree with me, but it is common practice to use .bashrc more for entering aliases and functions. I would put anything to do with the environment in .bash_profile.

Bill

nx5000 12-13-2006 11:59 AM

Well disagree or not, don't care.
There is a manual page, people have to read it. You are right for alias and stuff: there shouldn't be any export command in bashrc files

This is the most common error found in Linux, bashrc, profile and such things. Amazing.

I agree with putting it in .bash_profile but it will only work if bash is invoked as bash, not as /bin/sh. Okay I'm fussy :)
Edit : won't work with dash,csh,.. for example

SW-ANIKY 12-13-2006 01:40 PM

Thanks a lot, to all. Problem solved.


All times are GMT -5. The time now is 10:40 AM.