Using alias after issuing 'su - user'


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using alias after issuing 'su - user'
# 8  
Old 01-11-2016
Sorry, but i think it is necessary to clear up some details:


Quote:
Originally Posted by ocbit
I have the following alias in my local user profile:
Code:
PS1=`logname`@`hostname -s`:'$PWD>'

First: This is NOT an alias. This is an environment variable. It happens that "PS1" is the variable which is used as (the normal) prompt (by the Korn shell, the bash and a few other shells), but it is still an environment variable.

Second: you should NOT USE backticks any more, because they are deprecated. If you want what you wrote above write it this way:

Code:
PS1=$(logname)@(hostname -s):'$PWD>'

Third: hostname -s is an AIX speciality (for "short hostname", that is: without the domain information) and quite dangerous to use. If you are in the habit of copying your resource file to every host you use, then: beware! On Solaris (and HP-Ux, for that matter, perhaps a few other UNIXes too) executing hostname -s as root will result in setting the hostname to "-s", which is hardly what you want. Use this instead:

Code:
hostname=$(hostname)
hostname="${hostname%%.*}"

which will do the same as hostname -s but without the danger of setting the hosts name.

Finally:

You seem to set your environment in your profile (perhaps ~/.profile), which is not the best place to do so. Do it in ~/.kshrc (for the Korn shell, for bash use ~/.bashrc) instead. The difference is that the profile is executed exactly once - when you log in. The resource file is executed every time a new shell instance starts. This way you start every new shell you open, regardless of your session and how much you changed the environment of your current shell, with the same clean and predictable environment.

I hope this helps.

bakunin

Last edited by bakunin; 01-11-2016 at 06:32 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add file extensions to files EXCEPT the script that is issuing

Greetings all, On a RedHat System - I am issuing a command from script.sh that will add a file extension to a listing of files in a directory. It works, but I need to script from having an extension added as well. Here is what I have tried to no luck: for file in `ls * | awk ' /\./{print... (6 Replies)
Discussion started by: jeffs42885
6 Replies

2. Homework & Coursework Questions

Time command issuing all zeroes (is now considered homework help)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: A common problem arising in games and simulations is to generate a random arrangements of integers from 1 to N.... (5 Replies)
Discussion started by: lamentofking
5 Replies

3. UNIX for Dummies Questions & Answers

Time command issuing all zeroes

I am trying to issue the time command on a program so I can see execution times but it is returning all zeroes. Like this: time pdriver arg1 arg2 0.000u 0.000s 0:00.00 0.0% 0+0k 0+0io 0pf+0w "0+0k 0+0io 0pf+0w" --> The "0+0io" may change sometimes to a different number. How can I run the... (2 Replies)
Discussion started by: lamentofking
2 Replies

4. Red Hat

Postfix - want to send email to some non-existent user using alias

Hi, I know how to use email redirection using /etc/aliases file + postfix combination and it is working fine for existing users. The question I have is: I want to send an email to tony@server1.example.com while tony user is actually not there. Rather, I want to redirect that email to... (0 Replies)
Discussion started by: freebird8z
0 Replies

5. Shell Programming and Scripting

Matching user alias's to their ID's in the passwd file

Hi, I've a user alias file in the below format.. I need to change all the ID's that come after the = sign (with some multiple ID's which are separated by comma's) to their respective users that are contained in the passwords file.. Whats the best way to go about this.. Some sort of sed command in... (2 Replies)
Discussion started by: Jazmania
2 Replies

6. UNIX for Dummies Questions & Answers

Create alias files (not alias commands)

If one: $ find -name 'some expression' -type f > newfile and then subsequently wants to create an alias file from each pathname the find command retrieved and the > placed within 'newfile', how would one do this? Ideally, the newly created alias files would all be in one directory. I am... (3 Replies)
Discussion started by: Alexander4444
3 Replies

7. UNIX for Advanced & Expert Users

Issuing a Here Document as a Single Line Command

How can I run a here document on just one line? I ask, because I need to issue it from C++ as a system() or similar command and for security reasons I don't want to write out a shell script file from the program and run it. For example, how could I write: passwd test <<EOF n3wp3ss... (3 Replies)
Discussion started by: BrandonShw
3 Replies

8. Shell Programming and Scripting

Setting alias for a user - Linux ubuntu

Hi i have a user "SYSTEM" i want to set the below command in his .profile for an alias: who | awk '{print $1}'| sed '/SYSTEM/d' | sed '/root/d' |xargs -i pkill -u {} i tried as below: alias stop = " who | awk '{print $1}'| sed '/SYSTEM/d' | sed '/root/d' |xargs -i pkill -u {}" ... (3 Replies)
Discussion started by: joycesolomon
3 Replies

9. Linux

Error in issuing a make and make install

Hi, Recently I install a package and try to do a make and make install. However, in the make it gives me below error:- make:Nothing to be done for 'install-exec-am' make:Nothing to be done for 'install-data-am' Can anyone please explain to me what does this mean? I have been trying... (1 Reply)
Discussion started by: ahjiefreak
1 Replies

10. Shell Programming and Scripting

unix question: user supplied input for 'alias'

I have a program to scan the log files and I want to pipe the output to 'less'. I want to create an alias such that following are equivalent scanlog chunky.lst = /udd/n2man/utils/scanlog chunky.lst|less where chunky is user supplied file which can change. Is this possible as an alias or... (1 Reply)
Discussion started by: ospreyeagle
1 Replies
Login or Register to Ask a Question