-1

I am new to shell scripting

I am trying to dump directories in log file using the following method:

echo -n "Enter Starting Point : "; read SRC
echo $SRC
find $SRC -type d >log.txt

The output of the above code which is supposed to be saved in log.txt, is empty. If I write following code:

echo -n "Enter Starting Point : "; read SRC
echo $SRC
find ~ -type d >log.txt

it works fine. What is wrong with this code?

Michele La Ferla
  • 6,775
  • 11
  • 53
  • 79
Muh. Abdullah
  • 51
  • 1
  • 6

3 Answers3

0

I solved My problem by giving input as /home instead of '~' (without quotes)

Muh. Abdullah
  • 51
  • 1
  • 6
0

Use More Quotes™! This script won't work with various inputs. For example, if you want to search a directory called foo bar (with spaces), the find command will instead try to look into both foo and bar, which may not exist.

Also, ~ expansion is not trivial. If you want to pass your home directory to a script it's better to use $HOME.

l0b0
  • 55,365
  • 30
  • 138
  • 223
-1

~ is your home dir, so you dump the your home dir to log.txt, and 1st is your input dir to log.txt .

michael_stackof
  • 223
  • 3
  • 12