pwd in a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting pwd in a variable
# 1  
Old 12-02-2011
pwd in a variable

is there anyway i could store the output of pwd that is the path in a variable...?
# 2  
Old 12-02-2011
Yes...

You can store the password in the variable.. Here your password is stored in variable 'pass'.

Example:
---------
Code:
#cat pass.sh
password=123
echo -n "Enter pass:"
read pass
if [ $pass = $password ]; then
echo "Correct password"
else
echo "Wrong password"
fi


Last edited by Scott; 12-02-2011 at 05:54 AM.. Reason: Code tags
# 3  
Old 12-02-2011
no no not password... i am asking about pwd.. that is path of the file
#pwd
/htc/vivek
this path i need to store in a variable in script
# 4  
Old 12-02-2011
PHP Code:
vpath=`pwd
This User Gave Thanks to amitranjansahu For This Post:
# 5  
Old 12-02-2011
Hi,
I hope this is you are requesting.
Code:
$ pwd
/backup/shell
$ cat pwd.sh
#!/bin/sh
file=`pwd`
echo $file
$ sh pwd.sh
/backup/shell
$


Last edited by Scott; 12-02-2011 at 05:54 AM.. Reason: Code tags
This User Gave Thanks to thomasraj87 For This Post:
# 6  
Old 12-02-2011
thanks amitranjansahu and thomasraj..... :-) thanks a lotamitranjansahu Image
Registered User
# 7  
Old 12-02-2011
Hi.

You already have it, in $PWD.

If you want to take a copy of it, there's no need to "execute" pwd.

Code:
mypwd=$PWD

This User Gave Thanks to Scott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

How to pass value of pwd as variable in SED to replace variable in a script file

Hi all, Hereby wish to have your advise for below: Main concept is I intend to get current directory of my script file. This script file will be copied to /etc/init.d. A string in this copy will be replaced with current directory value. Below is original script file: ... (6 Replies)
Discussion started by: cielle
6 Replies

2. UNIX for Dummies Questions & Answers

$PWD vs `pwd`

Hi, can anyone expalin the real importance of PWD as a variable. However pwd command and $PWD is going to give the same result, then why do we have 2 different things. Please give some example which illustrates the difference between both. Thanks (9 Replies)
Discussion started by: pandeesh
9 Replies

3. UNIX for Dummies Questions & Answers

pwd help

Dear users, One more question, In unix when i use pwd the following I get: pwd /Users/username/src/directory name Is there a way to get the out put like this in which the if there is a space in the directory eg directory name it should show as directory\ name:... (2 Replies)
Discussion started by: kevincobain2000
2 Replies

4. AIX

sync samba pwd with aix5.3 pwd

currently, my samba login works just fine. i want my clients to use aix5.3 account to login to samba so they don't have to change samba pwd and aix pwd. i googled, and vi /usr/lib/smb.conf per some of knowledge base, but i could not get to work. aix5.3 and samba 3.0.24.0 thanks in advace..... (2 Replies)
Discussion started by: tjmannonline
2 Replies

5. Shell Programming and Scripting

how to assign a pwd value to a variable

Hi, I want to assign a pwd value to a variable filepath=$pwd Thx in advance (4 Replies)
Discussion started by: vls1210
4 Replies

6. UNIX for Advanced & Expert Users

echo ${PWD#${PWD%/*/*}/}

Can anyone explain this in detail ... echo ${PWD#${PWD%/*/*}/} Thanks in Advance (1 Reply)
Discussion started by: sakthi.abdullah
1 Replies

7. UNIX for Dummies Questions & Answers

PWD env variable

Could you please tell me, which process / file is responsible for the setting of PWD env variable in Solaris Thanks (1 Reply)
Discussion started by: chaandana
1 Replies

8. UNIX for Dummies Questions & Answers

pwd

Home directory mounted on one local system as /home/username, same directory mounted on a remote system as /home/engr/username. How to use command to use remote host pwd. For example rsh <remote host> ls -l ~pwd (2 Replies)
Discussion started by: bugsandbunny
2 Replies

9. Shell Programming and Scripting

help on PWD

Hi, We all know that pwd (or echo $PWD) gives us the present working dir as output.... but my doubt is that I'ld like to know how to get the present working folder - I mean - name of the current folder alone.. using pwd command I get the full folder name (right from root path)... I need to know... (2 Replies)
Discussion started by: mohanprabu
2 Replies

10. UNIX for Dummies Questions & Answers

PWD env variable for root

How do you get the $PWD env variable set for root? I know it's automatic for korn and other shells, but root uses /usr/bin/sh. (5 Replies)
Discussion started by: bcole23
5 Replies
Login or Register to Ask a Question