Reputation: 2111
I have a text file that contains a list of folder names, one per line, that I want to access in a directory. I intend to use the script as follows:
main.sh folderlist.txt foldername/
Here is the code:
#!/bin/bash
DIRFILE=$1;
INPUTBASEDIR=$2;
while read dir; do
echo "$INPUTBASEDIR$dir"
ls -l "$INPUTBASEDIR$dir"
done<"$DIRFILE"
When echoing the concatenated path, it outputs the correct and existing path. However, the ls line spits out : No such file or directory. What must I do to have the second line properly output the files under that directory?
Upvotes: 1
Views: 1180
Reputation: 768
When echoing the concatenated path, it outputs the correct and existing path.
One cannot be sure it is "correct and existing path". Command echo
simply outputs the argument string. Whether the file/directory exists or not does not matter.
Only ls
looks for the file. So it appears to me that there are some entries in folderlist.txt
which are not in foldername
.
Upvotes: 1