.bashrc files modifying the PS1 variable?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting .bashrc files modifying the PS1 variable?
# 1  
Old 11-09-2008
.bashrc files modifying the PS1 variable?

Is there a command for finding all files on the system named ".bashrc" that modify the PS1 variable? I'd like to list the full file name(s) and the protection (including the full path).
# 2  
Old 11-10-2008
...please...?
# 3  
Old 11-10-2008
Code:
ls -l $(grep -l PS1= $(find / -name .bashrc))

# 4  
Old 11-10-2008
With all due respect, wempy's code will work but is a bit "heavy". Using find here is usually better:
Code:
find / -type f -name .bashrc -exec grep -l PS1= "{}" ";"

Since one would only expect .bashrc's do be in directories like /home/xxx/.bashrc, you can make the search faster with:
Code:
for home in /home/*; do
  test -f $home/.bashrc && grep -l PS1= $home/.bashrc
done

If you have users spread throughout the filesystem, for some strange reason, you can use getent to get all home directories:
Code:
getent passwd |awk -F: '{ print $6 }' |
while read home; do
  test -f $home/.bashrc && grep -l PS1= $home/.bashrc
done

# 5  
Old 11-10-2008
Quote:
With all due respect, wempy's code will work but is a bit "heavy". Using find here is usually better:
Code:
find / -type f -name .bashrc -exec grep -l PS1= "{}" ";"

Hmm, I thought that I had limited the number of processes that are started here by using my method.
Code:
ls -l $(grep -l PS1= $(find / -name .bashrc))

starts only 3 processes (1 ls, 1 grep and 1 find), whereas yours will start 1 find and any number of grep processes depending on how many files find, er, finds.
I'm not disagreeing with you though that the place to look would be under home, and to only explicitly search in the root of the users home directories.
# 6  
Old 11-10-2008
You have a good point, especially if the number of users is greater than 2 (and it usually is). However, in my defense, it's to be expected that the number of .bashrc files are relatively small compared to the overall execution time of the find. Also, in a very very large user-base, and in cases where directory names have funny characters (like spaces), the $() solution may produce unexpected or incorrect results.

My solution could also be made better with xargs.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Modifying the .bashrc

I have modified the .bashrc. The problem is that when I write a long command, it does not write on the next line but continues to write on the same line. # ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for... (1 Reply)
Discussion started by: kristinu
1 Replies

2. UNIX for Dummies Questions & Answers

setting the PS1 variable

Hi i'm new to unix, can anyone assist in me setting the PS1 variable in unix (3 Replies)
Discussion started by: user@123
3 Replies

3. Shell Programming and Scripting

Please explain below PS1 variable

please tell me what is "!" mean in below value of PS1 variable PS1='($PWD) !>' Thanks Sunny (3 Replies)
Discussion started by: sunilmenhdiratt
3 Replies

4. Shell Programming and Scripting

.bashrc/PS1 command color different color to command output

I have been configuring my .bashrc PS1 to be displayed with some nice colors and in a format that I like, however there is one thing that I cannot figure out (or know if it's even possible). my PS1 line is as follows: export PS1='\\u\@\\h\:\\w\n\\$ \'This makes the command and command output... (0 Replies)
Discussion started by: jelloir
0 Replies

5. Solaris

problem in setting PS1 variable

Hi I have set PS1 in my profile as - PS1='${LOGNAME}@${PWD}>' ; export PS1 it works fine if I am in bash/ksh shell, but as soon as i switch to bourn shell (sh) then it shows "${LOGNAME}@${PWD}>" as prompt. It is also not working in csh. Please help. (3 Replies)
Discussion started by: sanjay1979
3 Replies

6. UNIX for Dummies Questions & Answers

Finding files that midify the PS1 variable.

Any help developing a command to find all files on the system named ".bashrc" that modify the PS1 variable. I wanna list the full file name, including the full path, and protection. Nothing else. (2 Replies)
Discussion started by: raidkridley
2 Replies

7. Shell Programming and Scripting

reading ~/.bashrc variable

1) I've added a variable called IMPORT_HOME to my ~/.bashrc file: IMPORT_HOME=/import:$IMPORT_HOME 2) I sourced the bashrc file: source ~/.bashrc 3) In my bash script, i tried to echo out the IMPORT_HOME variable but it doesnt print out '/import/, only whitespace: #!/bin/bash echo... (2 Replies)
Discussion started by: nuGz
2 Replies

8. UNIX for Dummies Questions & Answers

setting PS1 variable

Hi, I am trying to set my current prompt with the current directory iam working on by $PS1=$PWD but it is blank. please help. (4 Replies)
Discussion started by: papachi
4 Replies

9. UNIX for Advanced & Expert Users

PS1 variable

I want to set my prompt to something more descriptive than a plain old $, so I set the PS1 variable as such: PS1="" Which changes the prompt correctly, but when I change directories, it does not update the prompt. So I tried this: PS1="`pwd`>" I get the same results when changing... (2 Replies)
Discussion started by: dangral
2 Replies

10. UNIX for Dummies Questions & Answers

Very simple question about changing PS1 variable at startup!

Hello there ! I am new in this Unix world and just start learning Unix. I have very simple question about changing PS1 variable (Shell Prompt) i have local.profile file in my working directory, i open in vi edit mode and add this line PS1="Hello:>" and i save that file. I disconnected from... (2 Replies)
Discussion started by: abidmalik
2 Replies
Login or Register to Ask a Question