Home » Infrastructure » Unix » Cut user from pwd result
Cut user from pwd result [message #182258] Fri, 14 July 2006 00:49 Go to next message
kmsalih
Messages: 197
Registered: March 2006
Senior Member
Hi,

pwd will give the current directory.

Example

/home/user/dir1


I want to cut user from the pwd result.

The length of the username will change.

Is it possible?

Regards
Salih

[Updated on: Fri, 14 July 2006 01:17]

Report message to a moderator

Re: Cut user from pwd result [message #182290 is a reply to message #182258] Fri, 14 July 2006 03:34 Go to previous messageGo to next message
Frank Naude
Messages: 4565
Registered: April 1998
Senior Member
Try:

echo ${PWD#/home/user/}
Re: Cut user from pwd result [message #182592 is a reply to message #182290] Mon, 17 July 2006 03:49 Go to previous messageGo to next message
kmsalih
Messages: 197
Registered: March 2006
Senior Member
Hi Frank,

echo ${PWD#/home/user/}

The command you had posted is same as pwd command.

I want to cut only username from the result of pwd command



Regards
Salih KM



Re: Cut user from pwd result [message #182619 is a reply to message #182592] Mon, 17 July 2006 06:48 Go to previous messageGo to next message
tarundua
Messages: 1080
Registered: June 2005
Location: India
Senior Member

Run the following
 $ pwd | cut -d "/" -f3
Re: Cut user from pwd result [message #182673 is a reply to message #182619] Mon, 17 July 2006 09:31 Go to previous messageGo to next message
Frank Naude
Messages: 4565
Registered: April 1998
Senior Member
Well, it should work. Here is an example:

$ DIR=/home/user/dir1
$ echo ${DIR#/home/user/}
dir1
Re: Cut user from pwd result [message #182860 is a reply to message #182673] Tue, 18 July 2006 07:42 Go to previous messageGo to next message
kmsalih
Messages: 197
Registered: March 2006
Senior Member
Thanks to tarundua and Frank.

Both are working.

Tarundua's answer satisfied my requirement.

$pwd 
/home/oracle
$pwd | cut -d "/" -f3
oracle


Regards
Salih KM

[Updated on: Tue, 18 July 2006 07:47]

Report message to a moderator

icon14.gif  Re: Cut user from pwd result [message #182939 is a reply to message #182258] Tue, 18 July 2006 18:09 Go to previous message
lmraochodisetti
Messages: 2
Registered: July 2006
Location: mumbai
Junior Member

HI,
u will do simply like.
$ basename \home\user
it gives the user name.ok

eg: $ BASENAME \home\naani > some variable
result : naani.
Previous Topic: Problem-Report generation using shell script
Next Topic: Need help with Unix ksh exp/imp script
Goto Forum:
  


Current Time: Mon Nov 30 11:17:45 CST 2020