Making use of PWD command in the code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Making use of PWD command in the code
# 1  
Old 02-17-2012
Making use of PWD command in the code

Hi all,
Need some help in the following code. (Running this code at cygwin in windows vista)

Code:
cat /home/ebanpan/Input_Logs/*.log > /home/ebanpan/Input_Logs/input.log
sed '/^Total/d;/^Bye/d;/^Output has been logged/d' /home/ebanpan/Input_Logs/input.log > /home/ebanpan/output.log

this code works perfectly fine.
The directory home/ebanpan will be different for each PC user and this is my PWD.
So instead of writing home/ebanpan in the code everywhere, i want to make this directory same for each user (e.g. by PWD command, (home/ebanpan, home/enamuak, home/ekarjst etc)).

please help me out with this. (please get back to me for any doubts)

Last edited by Scott; 02-17-2012 at 10:21 AM.. Reason: Code tags
# 2  
Old 02-17-2012
There is no command called "PWD". There is a command called "pwd" which replies with the current working directory and in some Shells (we don't know what Shell you are using) the environment variable $PWD is the current working directory.

For your script the value of $HOME (current home directory) would be more appropriate if each user is to execute the script after logging in.
Not at all clear who will be logged in at the time the script will be run.
# 3  
Old 02-17-2012
If your shell has a PWD variable built-in:
Code:
cat ${PWD}/Input_Logs/*.log > ${PWD}Input_Logs/input.log

If not:
Code:
# save the output of the pwd command in a variable.
mypath=$(pwd)
# If you have to use the older command substitution if your shell does not support the above method:
mypath=`pwd`
 
cat ${mypath}/Input_Logs/*.log > ${mypath}Input_Logs/input.log

Note: not tested as I do not have cygwin installed, but you get the idea.

Consider using $HOME (there's no place like $HOME heh) or the shortcut for $HOME, "~":
Code:
cat ~/Input_Logs/*.log > ~/Input_Logs/input.log


Last edited by gary_w; 02-17-2012 at 12:32 PM..
# 4  
Old 02-17-2012
Hi,
thanks a lot for replying!!
Its working perfectly fine. thanks very much. Smilie
# 5  
Old 02-17-2012
@bansalpakaj88
We'd love to see the final code which is working.
# 6  
Old 02-18-2012
Hi,
Here is code which i wrote with the help of you guys. it is pretty straight forward.
Code:
cat ${PWD}/Input_Logs/*.log >  ${PWD}/Input_Logs/input.log
sed '/^Total/d;/^Bye/d;/^Output has been logged/d'  ${PWD}/Input_Logs/input.log? >  ${PWD}/output.log

Smilie

Last edited by Franklin52; 02-18-2012 at 02:50 PM.. Reason: Please use code tags for data and code samples, thank you
# 7  
Old 02-18-2012
Unless you oddly set PWD with something not your current directory, there is no need to use this variable in your script. It is equivalent to:

Code:
cat Input_Logs/*.log > Input_Logs/input.log
sed '/^Total/d;/^Bye/d;/^Output has been logged/d' Input_Logs/input.log? > output.log

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Command Understanding :- . $PWD/.profile

Hi, I am new in unix, can anyone please explain the use of:- . $PWD/.profile Thanks, Sujoy (5 Replies)
Discussion started by: sujoyrchowdhury
5 Replies

2. Shell Programming and Scripting

Help with 'pwd' command

Dear all, I am trying to use 'pwd' command in following way. current_directory == /dirA/dirB/test/dirC if ; then do this fi I am not sure how to pass this in command way. Please help! thanking you, emily (10 Replies)
Discussion started by: emily
10 Replies

3. Shell Programming and Scripting

Behaviour of pwd command in sh and ksh

I have a script as below. bash-3.00$ cat test.sh #!/usr/bin/ksh path=`pwd` echo $path var=$path/temp11 echo $var If run it is giving output bash-3.00$ ksh test.sh //var/tmp/SB2/miscellaneous //var/tmp/SB2/miscellaneous/temp11 (5 Replies)
Discussion started by: millan
5 Replies

4. Shell Programming and Scripting

How to pass the pwd to an export command through script?

I have an export command which exports the file which I specify to the specified location. It asks for an pwd and again to confirm the pwd, can some one help me to pass the pwd thru the script. cd /opt/var/SecureTransport/bin xml_export /opt/SecureTransport/var/logs/accounts_log.xml... (3 Replies)
Discussion started by: srini0603
3 Replies

5. 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

6. UNIX for Dummies Questions & Answers

PWD COMMAND

Hi, Can you tell me if there is a command such as pwd which does not give me the absolute NFS pathname i.e. it starts with .autofs? At the moment on the unix when I use the 'pwd' command it always gives me the nfs pathname rather thanthe local pathname of which is what i want, is there an... (4 Replies)
Discussion started by: cyberfrog
4 Replies

7. UNIX for Dummies Questions & Answers

COMMAND sed AND pwd

Hi, I should replace the string DIR_ZERO in the file FILE_OLD with the current directory path in FILE_NEW by using something like this: sed "s/DIR_ZERO/'$(pwd)'/" FILE_OLD > FILE_NEW but it doesn't work and I don't understand why...:confused: Thanks in advance!!! Giordano Bruno (2 Replies)
Discussion started by: Giordano Bruno
2 Replies

8. IP Networking

Enable PWD command on anonymous FTP?

Hello everyone - First post here, I'm trying to connect to an anonymous ftp server and I am told by the server admin that I cannot have access to the "print working directory" command. I need to have access to this command in order for my (and my clients) preferred ftp client to connect. (the... (9 Replies)
Discussion started by: HiredGun79
9 Replies

9. UNIX for Dummies Questions & Answers

pwd: A specified flag is not valid for this command.

Probably a very straight forward question but please be easy on me, I am v. new to UNIX! A script that I have runs the line tmp=`pwd -H` It works fine, but I needed to make a couple of other changes to the script, nowhere near this line but now this line reports: pwd: A specified flag... (2 Replies)
Discussion started by: Paxton
2 Replies

10. UNIX for Dummies Questions & Answers

pwd Command and NIS mount points

I am running NIS, NFS and automount. If I execute % cd /xyz/data1 % pwd I get different results depending on the operating system. On SGI running Irix 6.5.x pwd returns /xyz/data1 On Redhat Linux 7.3 pwd returns /xyz/data1 BUT On Tru64 UNIX the pwd command returns... (1 Reply)
Discussion started by: agreenwo
1 Replies
Login or Register to Ask a Question