BASH script
i want to write a script. i am using centos 6 x64.
basically i want to write a script in which i need to go to home directory of user in every machine. but i dont remember the username of every user. so what is the simbol to use before username. script is something like below. basically i want to enter something in .bashrc file for every user. Code:
echo "export LD_LIBRARY_PATH=/opt/R-2.15.2/lib:$LD_LIBRARY_PATH" >> /home/$username/.bashrc |
The symbol is tild (~)
If you use Code:
cd ~ If you use Code:
cat ~/.bashrc |
Quote:
could you help me to know how can i achieve this task. |
If you are root and you have to go to the user's home directory and if there is only one directory in /home
Code:
#!/bin/bash If you are root and you have to go to the user's home directory and if there are more than one directory in /home Code:
i=1 |
*EDIT jpollard makes a very valid point. You should refer to his post #7 instead of mine.
Not all users necessarily have their home directory in /home. ~ and ~user will require you to know the usernames beforehand. Your best bet is to parse /etc/passwd for users greater than some UID. In my case uid >=1000 and excluding the nobody user. Take for example this entry in /etc/passwd... Code:
sam:x:1000:1000:Sam,,,:/home/sam:/bin/bash Code:
awk 'BEGIN {FS=":"};$3 > 999 && $1 != "nobody" {print $6}' /etc/passwd Code:
#!/bin/bash |
If you have multiple users on each machine, you will want to apply this to each user no? So maybe something like:
Code:
list1=$(ls /home) |
Why would you add that to every user?
Put it in the /etc/profile or /etc/bashrc and let everyone get it at once. Makes it easier to adjust later instead of just accumulating more errors as the system evolves. |
Thnx guys for your support.
i was looking exactly same stuff. |
All times are GMT -5. The time now is 07:03 PM. |