Link to home
Start Free TrialLog in
Avatar of sunny82
sunny82

asked on

How to kuu to another id inside a shell script

I need to kuu within a script and then exit from the kuu id within the same script. How can I do that?




#!/bin/ksh

cd ~

filename = $(ls -ltr | awk 'END{print $NF}'
kuu pfndqa
./run-dfp.sh qae2e first /v/TgtFiles/$filename
exit
cd /v/region/na/appl/

Open in new window

Avatar of sunny82
sunny82

ASKER

On doing kuu here, it is asking me for pasword but on putting the password, it should execute the following shell script. But it is not getting executed. After executing the shell script, it should then exit the kuu id
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
... and the statement in line 5 will most probably not do what you want.

I assume you're trying to find the newest file in the directory.
This is easier:

filename=$(ls -tr | tail -1)

Note that I removed the spaces around "=". They're not allowed when assigning variables.


Avatar of sunny82

ASKER

Thx so much..let me try this tomorrow and I will let you know...I am assuming that after doing su and calling this shell script from another perl or shell script, it will ask for my password and after executing line 7 will exit the su and return to my actual user id. Am I correct?
Yes, correct.
Just note that everything you want to execute as pfndqa must appear after "-c" and must be enclosed in quotes.
In your case use double quotes, because there is the local variable $filename which needs to get expanded by the calling shell, not the subshell opened by "su".
Should you need double quotes inside the command executed via "su" escape them with a backslash (\")
You don't need an explicit "exit". When the command specified with -c "..." ends the subshell ends as well.
Avatar of sunny82

ASKER

great that helped a lot. Thx..I would like to know the difference between su and kuu...Don't both do the same thing?
I still have no idea what kuu actually is. Nerver heard of it before, and searching the web doesn't yield any suitable result.
Could it be that kuu is an alias or a link?
Please issue
alias kuu
type kuu
ls -l $(which kuu)
Any insight?
Thx for the points!
wmp