T
T
Talyan2020-02-27 16:46:57
linux
Talyan, 2020-02-27 16:46:57

Where does the triple from the number 36 disappear?

I have a poltergeist going on here. I don't see an error.

I receive a list of UIDs of letters from the mailbox via IMAP using CURL, which I am going to process further:

#!/bin/bash
#ставлю англ. локаль чтобы date выдал <b>Feb</b> вместо <b>Фев</b>
LANG=en_US.utf8
DATE_STRING=`date +"01-%h-%Y"`
#отрезаю из ответа IMAP первые 9 символов из строки ( * SEARCH 2 3 4 10 20 34 35 36)
MAIL_LIST_CMD=`curl -s  "imap://me%40site.ru:[email protected]/INBOX?SINCE%2001-feb-2020%20from%20abon.site.ru" | cut -c 9-`


MAIL_LIST_CMD then looks like this:
2 3 4 10 20 34 35 36

Next, the usual loop:

for i in $MAIL_LIST_CMD
do

        echo -e "$i \n"
done


and I get this error:
2
3
4
10
20
34
35
6


And even (!!) if I do this: Then I get the same nonsense:
MAIL_LIST_CMD="$MAIL_LIST_CMD 37 38"

2
3
4
10
20
34
35
6
37
38


Where are the three going?
If I echo $MAIL_LIST_CMD at the end of the whole code, then I get a perfectly normal series with the number 36 at the end.

P/S:

Decided to try this: Got:
echo $(($i+1-1))

2
3
4
10
20
34
35
+1-1»)ошибка синтаксиса: недопустимый математический оператор (неверный маркер «


That is, in the last number from CURL'a 36 is drawn with some left extra character.
How can I fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Talyan, 2020-02-27
@flapflapjack

the problem was solved like this:

MAIL_LIST_CMD=`echo -e "$MAIL_LIST_CMD" | tr -d '\r\n'`

There was an extra carriage return

S
Saboteur, 2020-02-28
@saboteur_kiev

and so?

for i in $MAIL_LIST_CMD
do
        echo "$i "
done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question