Using alias after issuing 'su - user'


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using alias after issuing 'su - user'
# 1  
Old 01-05-2016
Using alias after issuing 'su - user'

Hi,

Using ksh, I have set up aliases (which work fine) in my user's .profile like this:

Code:
alias ll = 'ls -lrt'

Code:
alias cls = 'clear'

How do I call these same aliases so that they will work after issuing this: ?
Code:
su - user

I do not want to add aliases to the su shell's .profile or .kshrc.
# 2  
Old 01-05-2016
Just source in your aliases after the su.
Code:
. /path/to/your/aliases.ksh

This User Gave Thanks to cjcox For This Post:
# 3  
Old 01-05-2016
Awesome. Thank you!
# 4  
Old 01-07-2016
Quote:
Originally Posted by ocbit
How do I call these same aliases so that they will work after issuing this: ?
[...]
I do not want to add aliases to the su shell's .profile or .kshrc.
By setting the variable "ENV" you can designate a resource file to be used for shell startup. per default this resource file is ~/.kshrc, which is why this gets executed at shell startup.

Since you probably have several people using the root-account and want everybody have its own configuration being read, put the following into root's profile to set the environment according to the user you came from:

Code:
origuser="$(who -lm)"
origuser="${%% *}"

exec ENV="~${origuser}/.kshrc"
export ENV

Attention: i am not sure if "-l" and "-m" are standard options for who. On AIX the exist doing:

Quote:
Code:
       -l
            Lists any login process.
       -m
            Displays information about the current terminal only. The who -m
            command is equivalent to the who am i and who am I commands.

You might need to adapt the command accordingly.

I hope this helps.

bakunin
# 5  
Old 01-11-2016
I have the following alias in my local user profile:
Code:
PS1=`logname`@`hostname -s`:'$PWD>'

This appears as:
Code:
user@machineName:/home/user>

How can I make the logname parameter reflect the su user after su'ing?

So it would look like:
Code:
suUser@machineName:/home/suUser>

# 6  
Old 01-11-2016
Try
Code:
PS1='\u@\h:$PWD>'

That's bash.
Other shells might take
Code:
if [ -z "$USER" ]; then
 export USER
 USER="$LOGNAME"
 if [ -z "$USER" ]; then
  USER=`PATH=/bin:/usr/bin:/usr/ucb whoami`
 fi
fi
if [ -z "$HOST" ]; then
 HOST=`uname -n | cut -f1 -d.`
 export HOST
fi
PS1='$USER@${HOST}:$PWD>'


Last edited by MadeInGermany; 01-11-2016 at 01:55 PM..
This User Gave Thanks to MadeInGermany For This Post:
# 7  
Old 01-11-2016
Second solution worked like a charm.
 
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