问题
I am trying to test if certain files, called up in a list of textfiles, are in a certain directory. Every once in a while (and I am quite certain I use the same statements every time) I get an error, complaining that the echo
command cannot be found.
The textfiles I have in my directory /audio/playlists/
are named according to their date on which they are supposed to be used: 20130715.txt
for example for today:
me@computer:/some/dir# ls /audio/playlists/
20130715.txt 20130802.txt 20130820.txt 20130907.txt 20130925.txt
20130716.txt 20130803.txt 20130821.txt 20130908.txt 20130926.txt
(...)
me@computer:/some/dir# cat /audio/playlists/20130715.txt
#A Comment line goes here
00:00:00 141-751.mp3
00:03:35 141-704.mp3
00:06:42 140-417.mp3
00:10:46 139-808.mp3
00:15:13 136-126.mp3
00:20:26 071-007.mp3
(...)
23:42:22 136-088.mp3
23:46:15 128-466.mp3
23:50:15 129-592.mp3
23:54:29 129-397.mp3
So much for the facts. The following statement, which lets me test
if all files called upon in all of the textfiles in the given directory are actually a file in the directory /audio/mp3/
, produces an error:
me@computer:/some/dir# for i in $(cat /audio/playlists/*.txt|cut -c 10-16|sort|uniq); do [ -f "/audio/mp3s/$i.mp3" ] || echo $i; done
echo: command not found
me@computer:/some/dir#
I would guess bash
wants to complain about the "A Comment"-line (actually " line "
) not being a file, but why would that cause echo
not to be found? Again, mostly this works, but every so often I get this error. Any help is greatly appreciated.
回答1:
That space before echo
isn't U+0020, it's U+00A0. And indeed, the command " echo"
doesn't exist.
来源:https://stackoverflow.com/questions/17648585/bash-wrong-behavior-in-for-loop-together-with-a-test-statement