Вопрос

I'm having trouble with this bit of linux code:

 FILE=$(wget 'https://dl.dropbox.com/s/ru72h4b984qpxxq/spotify.txt' -q -O -)

if [ "$FILE" == "|  |" ]
then
echo "File is a match"

I can't get this statement to be true. Would you mind checking the contents of the url and tell me if I'm doing something wrong with the vertical lines or spacing? Thanks for your help.

Это было полезно?

Решение

@MarkB's point is well taken: one usually uses the = single-equals in []. However, the specific problem in your case seems to be that wget is returning a stray \r carriage-return character. You can see this by

echo "$FILE" | hexdump -C

assuming that you have BSD utilities installed (which you probably do).

Here's one fix:

FILE=$(wget 'https://dl.dropbox.com/s/ru72h4b984qpxxq/spotify.txt' -q -O - | sed 's/\r//')
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top