I'm still pretty new to unix and scripting and I'm trying to write a script that can take an input directory from the user, check if it exists, then compare the number of files in the given directory to the current directory and report which has more files. My code mostly works, as long as I input a child directory. If I try and use the script and input a parent, or another child along a different branch, it cannot find the directory, even when given the full path. I know that similar questions were asked regarding the test command, but none (that I could find) addressed what to do when test can't recognize a directory that does, in fact, exist.
dir1=$(pwd) read -rp "Input the path..." dir2 if [ ! -d "$dir2" ]; then echo "...does not exist" else ...
...the remainder of the code works fine. This is where the troubles lie.
EDIT: The general idea is to find any directory from any other directory but that isn't happening. For example from my ~/public_html as pwd, if I run the script and input ~/schoolwork, or even the full path, it cannot recognize the directory.
I have also reversed the logic (so that my function checks if it exists, then performs the operations, else returns an error) as well as the method posted here. the results are the same.