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)

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)

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.

If your shell has a PWD variable built-in:

cat ${PWD}/Input_Logs/*.log > ${PWD}Input_Logs/input.log

If not:

# 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, "~":

cat ~/Input_Logs/*.log > ~/Input_Logs/input.log

Hi,
thanks a lot for replying!!
Its working perfectly fine. thanks very much. :b:

@bansalpakaj88
We'd love to see the final code which is working.

Hi,
Here is code which i wrote with the help of you guys. it is pretty straight forward.

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

:o

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:

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