Hi all!
I'm writing a shell script that will run pwd on the directory I am in and write the output to a text document for later use. However, I'm running into a couple of things I don't want it to do; I'm attributing that to lack of experience. :>)
First, the output of pwd is being printed to the screen as well as being written to the file. I know the problem is with the pwd == $HOME statement because if I remove it and the if statement leaving pwd >> paths.txt, the output is only printed to the file ~/paths.txt.
Second, I would like to make this script work only in the user's home directory. Mainly as an exercise in using if statements.
Is there any way to do this? As it is now, it works in all directories. Nothing wrong with that, of course, but I don't need an if statement to make it work that way.
Thanks!
I'm writing a shell script that will run pwd on the directory I am in and write the output to a text document for later use. However, I'm running into a couple of things I don't want it to do; I'm attributing that to lack of experience. :>)
First, the output of pwd is being printed to the screen as well as being written to the file. I know the problem is with the pwd == $HOME statement because if I remove it and the if statement leaving pwd >> paths.txt, the output is only printed to the file ~/paths.txt.
Second, I would like to make this script work only in the user's home directory. Mainly as an exercise in using if statements.
Code:
#! /bin/sh
if pwd == $HOME
then
pwd >> ~/paths.txt
fi
Thanks!