Сравните вывод скрипта PythonPython

Программы на Python
Anonymous
Сравните вывод скрипта Python

Сообщение Anonymous »


I would like to use bash as simple test system for my simple scripts.

Here is my example of bash test.sh:

test() { res=$(echo $1 | python test.py) printf "$res" | od -c printf "$2" | od -c if [ "$res" = "$2" ] then echo "OK" else echo "NOT OK" fi } test "1 2 3" "1\r\n2" And there is my simple python code test.py:

a = [int(i) for i in input().split()] print("{}".format(a[0])) print("{}".format(a[1])) The simple idea is to compare strings with a new line symbol "\n".

My output of bash:

$ bash test.sh 0000000 1 \r \n 2 0000004 0000000 1 \r \n 2 0000004 NOT OK It's confused to me that I have the same output of od function but bash can't recognize them as equals. Why does it happen?


Источник: https://stackoverflow.com/questions/780 ... hon-script

Вернуться в «Python»