I'm trying to count the number of files with different extensions in /foo/.
case 1 works as expected, but more flexible situations such as case 2 or case 3 don't work as expected.
File test.sh
# case 1
vista=$(find /foo/*.zip -atime -1)
echo "$vista" | wc -l
# case 2
vista=$(find /foo/*)
echo "$vista.zip -atime -1" | wc -l
# case 3
echo "$vista.xz -atime -1" | wc -l
Output:
./test.sh
187
4566
4566
I suspect the problem is that for example echo "$vista.zip -atime -1" from case 2 runs first find /foo/* before appending the string zip -atime -1, but I don't know how to do it right.
vista=$(find /foo/*)doesn't do anything like storing a command in the variable, it runs the command and stores its output in the variable. So it might setvistato something like "/foo/file1\n/foo/file2" (where the\nrepresents an actual newline character). Thenecho "$vista.zip -atime -1" | wc -lexpands toecho "/foo/file1\n/foo/file2.zip -atime -1" | wc -lwhich isn't even slightly close to what you want.