LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   .bashrc help (https://www.linuxquestions.org/questions/linux-newbie-8/bashrc-help-680120/)

xoxox 10-30-2008 06:07 PM

.bashrc help
 
Hi,

Im having quite of a bit of trouble with this one.

so far i have done:

find / -name .bashrc

to display all the .bashrc files on the system

-How can i tell which one ( if not all ) of these files modify the PS1 varaible?

Im guessing that the output is displaying the full path name. Although most paths have permission denied.

-What command can i use to display the file protection?

-When i redirect the output to an emacs file i only the /home entries


Again, all .bashrc files on the system and need the file protection and to redirect all of the output to a file.

Hints are appreciated.

abolishtheun 10-30-2008 06:19 PM

you can use grep for, say, "PS1=" to check if the PS1 variable is changed. and you must have permission to any file you read... so run the command as root or something.

chrism01 10-30-2008 06:41 PM

Expanding on the above, the only place a .bashrc file should exist is in the /home dirs. Its a user specific/customisable file, along with .bash_profile.
To show perms use
ls -l

i92guboj 10-30-2008 07:13 PM

Quote:

Originally Posted by xoxox (Post 3326635)
Hi,

Im having quite of a bit of trouble with this one.

so far i have done:

find / -name .bashrc

to display all the .bashrc files on the system

-How can i tell which one ( if not all ) of these files modify the PS1 varaible?

I'll respond with a quote from `man bash` (see that man page -search for "INVOCATION"- for more info).

Quote:

When bash is invoked as an interactive login shell, or as a non-interactive
shell with the --login option, it first reads and executes commands from the
file /etc/profile, if that file exists. After reading that file, it looks
for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads
and executes commands from the first one that exists and is readable. The
--noprofile option may be used when the shell is started to inhibit this
behavior.

When a login shell exits, bash reads and executes commands from the file
~/.bash_logout, if it exists.

When an interactive shell that is not a login shell is started, bash reads
and executes commands from ~/.bashrc, if that file exists. This may be
inhibited by using the --norc option. The --rcfile file option will force
bash to read and execute commands from file instead of ~/.bashrc.
Quote:

Im guessing that the output is displaying the full path name. Although most paths have permission denied.
Yep.

Quote:

-What command can i use to display the file protection?
If you mean, to see the permissions of the file, use ls -l which will display all the info. The permissions are the first thing on each row.

Quote:

-When i redirect the output to an emacs file i only the /home entries
Dunno what do you mean by "emacs file". Maybe it's a plain text file that you open in emacs(?), but in any case, all the output except maybe the errors should be redirected into the file. To output everything you can add ">myfile 2>&1" instead of just ">myfile".

xoxox 10-30-2008 07:43 PM

I need to add the protection to the " find / -name .bashrc " output

ls -lha .bashrc gives me the protection of the .bashrc file but not every .bashrc file on the system.

is there some way to link these commands together?


And the redirection worked nicely.

i92guboj 10-30-2008 07:51 PM

I answered a similar question here today:

http://www.linuxquestions.org/questi...ight=stat+find

However, why do you want to do so? Did you read the fragment of the man page I gave you? You will find .bashrc only on the home directory of your users, and nowhere else. And only the one for the current active user is relevant for you. I don't know what do you expect to find.

xoxox 10-30-2008 08:00 PM

lol neither do i.

but i want to get this right.

How do i know that any of these files modify the PS1 varaible?


i understand the ls -l all the files in my home directory

but insted of my /home the .bashrc files insted

chrism01 10-30-2008 08:09 PM

There is only one hidden .bashrc file in each user's home dir.
To see it, use
ls -a

if you want perms as well

ls -la

You can check for PS1 being set using grep

grep PS1 .bashrc

i92guboj 10-30-2008 08:29 PM

Quote:

Originally Posted by xoxox (Post 3326740)
lol neither do i.

Hehehe, well, right. Then it's time to learn, no one is born knowing everything.

Everything you need to know is in that bit of info I pasted from the bash man page. However, since I have some spare time right now I will explain it a bit better for you.

You can consider /etc/profile like kind of a global bash configuration file. You shouldn't ever need to change it, unless you know what you are doing (and in that case, you wouldn't be asking here).

So, that leaves one less option. For the rest...

If you login on text mode, in a pure text console outside X, then bash will be in login mode (easy to understand). In login mode, bash reads one and only one amongst these files: ~/.bash_profile, ~/.bash_login, and ~/.profile. Bash looks for them in that same order, and only the first one found is used, even if it's an empty file (as long as you have read permissions over them).

If you didn't log in text mode, then you will be accessing bash using an xterm or a similar terminal emulator (konsole, gnome-terminal, urxvt or whatever). Then bash is in non-login mode. In this case, the relevant file is ~/.bashrc.

So, there you are: that's the info you need. If you want to change the value of PS1, just put it in the right file, and it will work. If these files do not exist, just create them using a regular text editor and make sure you name them correctly, starting with a dot.

PTrenholme 10-30-2008 08:34 PM

Since you're using the find command, consider using the -exec grep -H PS1 {} option to implement Chris' suggestion. (You will, of course, need to prepend the find with a sudo or su -c, or just run in a root shell.)

xoxox 10-30-2008 09:39 PM

i found a simlar command:

find . -type f | xargs grep .bashrc


But im not sure if these files modify the PS1 varaible. LOL

And the files are mostly bash_history

onebuck 10-30-2008 10:04 PM

Hi,

I'm not sure as to your reasoning but if you would read the 'man bash' then things may clear up.

Code:

excerpt 'man bash';

 When bash is invoked as an interactive login shell, or as a  non-inter-
      active  shell with the --login option, it first reads and executes com-
      mands from the file /etc/profile, if that file exists.  After  reading
      that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
      in that order, and reads and executes commands from the first one  that
      exists  and  is  readable.  The --noprofile option may be used when the
      shell is started to inhibit this behavior.

      When a login shell exits, bash reads and  executes  commands  from  the
      file ~/.bash_logout, if it exists.

      When  an  interactive  shell that is not a login shell is started, bash
      reads and executes commands from ~/.bashrc, if that file exists.  This
      may  be inhibited by using the --norc option.  The --rcfile file option
      will force bash to read and  execute  commands  from  file  instead  of
      ~/.bashrc.

Below is an example of a '.bashrc' that I use on my systems. Very useful for the user. I really don't see the need to modify the 'PS1=' within '.bashrc' system wide. What is your reasoning?

Code:

#.bashrc
#08-30-06 12:17 gws copied loki:/home/gws
# Add bin to path
export PATH="$PATH:$HOME/bin"

# Dynamic resizing
shopt -s checkwinsize

# Custom prompt
#
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

#08-29-06 11:40 gws

#if [ `id -un` = root ]; then
#  PS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] '
# else
#  PS1='\[\033[1;32m\]\h:\w\$\[\033[0m\] '
#fi
#
# Add color
eval `dircolors -b`

# User defined aliases
alias cls='clear'
alias clls='clear; ls'
alias ll='ls -l'
alias lsa='ls -A'
alias lsg='ls | grep'
alias na='nano'
alias web='links -g -download-dir ~/ www.google.com'

#08-29-06 11:45 gws
#To clean this up and cover your tracks once you log off

#Depending on your version of BASH, you might have to use
# the other form of this command
  trap "rm -f ~$LOGNAME/.bash_history" 0

#The older KSH-style form
#  trap 0 rm -f ~$LOGNAME/.bash_history

Notice the '.bash_profile';

Code:

# .bash_profile
#08-30-06 12:18 copied loki:/home/gws

# Source .bashrc
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi



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