1

I have 2 version of the same shell script file. ASCII wise they are Identical (Used Notepad++ Compare Plugin), but only one executes correctly.

I ran FC /B on the windows command line to compare them at a binary level it it says they are different.

how can this happen?

Note: this is a Raspbian shell script that I wrote.

Output of the FC command

Comparing files start-NotWorking.sh and START-WORKING.SH
0000000B: 0D 0A
0000000C: 0A 23
0000000D: 23 4C
0000000E: 4C 61
0000000F: 61 75
00000010: 75 6E
00000011: 6E 63
00000012: 63 68
00000013: 68 20
00000014: 20 4C
00000015: 4C 6F
00000016: 6F 67
00000017: 67 20
00000018: 20 46
00000019: 46 69
0000001A: 69 6C
0000001B: 6C 65
0000001C: 65 20
0000001D: 20 52
0000001E: 52 65
0000001F: 65 61
00000020: 61 64
00000021: 64 65
00000022: 65 72
00000023: 72 20
00000024: 20 57
00000025: 57 65
00000026: 65 62
00000027: 62 20
00000028: 20 53
00000029: 53 65
0000002A: 65 72
0000002B: 72 76
0000002C: 76 65
0000002D: 65 72
0000002E: 72 0A
0000002F: 0D 5F
00000030: 0A 49
00000031: 5F 50
00000032: 49 3D
00000033: 50 22
00000034: 3D 24
00000035: 22 28
00000036: 24 68
00000037: 28 6F
00000038: 68 73
00000039: 6F 74
0000003A: 73 6E
0000003B: 74 61
0000003C: 6E 6D
0000003D: 61 65
0000003E: 6D 20
0000003F: 65 2D
00000040: 20 49
00000041: 2D 29
00000042: 49 22
00000043: 29 0A
00000044: 22 65
00000045: 0D 63
00000046: 0A 68
00000047: 65 6F
00000048: 63 20
00000049: 68 22
0000004A: 6F 49
0000004B: 20 50
0000004C: 22 20
0000004D: 49 61
0000004E: 50 64
0000004F: 20 64
00000050: 61 72
00000051: 64 65
00000052: 64 73
00000053: 72 73
00000054: 65 3A
00000055: 73 20
00000056: 73 24
00000057: 3A 5F
00000058: 20 49
00000059: 24 50
0000005A: 5F 22
0000005B: 49 0A
0000005C: 50 74
0000005D: 22 61
0000005E: 0D 69
0000005F: 0A 6C
00000060: 74 6F
00000061: 61 6E
00000062: 69 20
00000063: 6C 2D
00000064: 6F 66
00000065: 6E 20
00000066: 20 2F
00000067: 2D 75
00000068: 66 73
00000069: 20 62
0000006A: 2F 64
0000006B: 75 72
0000006C: 73 69
0000006D: 62 76
0000006E: 64 65
0000006F: 72 2F
00000070: 69 6C
00000071: 76 6F
00000072: 65 67
00000073: 2F 73
00000074: 6C 2F
00000075: 6F 72
00000076: 67 65
00000077: 73 63
00000078: 2F 65
00000079: 72 6E
0000007A: 65 74
0000007B: 63 2D
0000007C: 65 6C
0000007D: 6E 6F
0000007E: 74 67
0000007F: 2D 2E
00000083: 2E 20
00000084: 6C 2F
00000085: 6F 75
00000086: 67 73
00000087: 20 62
00000088: 2F 64
00000089: 75 72
0000008A: 73 69
0000008B: 62 76
0000008C: 64 65
0000008D: 72 2F
0000008E: 69 6C
0000008F: 76 6F
00000090: 65 67
00000091: 2F 73
00000092: 6C 2F
00000093: 6F 6C
00000094: 67 6F
00000095: 73 67
00000096: 2F 73
00000097: 6C 2D
00000098: 6F 69
00000099: 67 6E
0000009A: 73 66
0000009B: 2D 6F
0000009C: 69 72
0000009D: 6E 6D
0000009E: 66 61
0000009F: 6F 74
000000A0: 72 69
000000A1: 6D 6F
000000A2: 61 6E
000000A3: 74 2F
000000A4: 69 2A
000000A5: 6F 2E
000000A6: 6E 6C
000000A7: 2F 6F
000000A8: 2A 67
000000A9: 2E 20
000000AA: 6C 2F
000000AB: 6F 75
000000AC: 67 73
000000AD: 20 62
000000AE: 2F 64
000000AF: 75 72
000000B0: 73 69
000000B1: 62 76
000000B2: 64 65
000000B3: 72 2F
000000B4: 69 6C
000000B5: 76 6F
000000B6: 65 67
000000B7: 2F 73
000000B8: 6C 2F
000000B9: 6F 6C
000000BA: 67 6F
000000BB: 73 67
000000BC: 2F 73
000000BD: 6C 2D
000000BE: 6F 77
000000BF: 67 61
000000C0: 73 72
000000C1: 2D 6E
000000C2: 77 69
000000C3: 61 6E
000000C4: 72 67
000000C5: 6E 73
000000C6: 69 2F
000000C7: 6E 2A
000000C8: 67 2E
000000C9: 73 6C
000000CA: 2F 6F
000000CB: 2A 67
000000CC: 2E 20
000000CD: 6C 2D
000000CE: 6F 62
000000CF: 67 20
000000D0: 20 22
000000D1: 2D 24
000000D2: 62 5F
000000D3: 20 49
000000D4: 22 50
000000D5: 24 3A
000000D6: 5F 38
000000D7: 49 30
000000D8: 50 22
000000D9: 3A 20
000000DA: 38 2D
000000DB: 30 61
000000DC: 22 20
000000DD: 20 26
000000DE: 2D 0A
000000DF: 61 23
000000E0: 20 45
000000E1: 26 6E
000000E2: 0D 64
000000E3: 0A 20
000000E4: 23 4C
000000E5: 45 61
000000E6: 6E 75
000000E7: 64 6E
000000E8: 20 63
000000E9: 4C 68
000000EA: 61 20
000000EB: 75 4C
000000EC: 6E 6F
000000ED: 63 67
000000EE: 68 20
000000EF: 20 46
000000F0: 4C 69
000000F1: 6F 6C
000000F2: 67 65
000000F4: 46 52
000000F5: 69 65
000000F6: 6C 61
000000F7: 65 64
000000F8: 20 65
000000F9: 52 72
000000FA: 65 20
000000FB: 61 57
000000FC: 64 65
000000FD: 65 62
000000FE: 72 20
000000FF: 20 53
00000100: 57 65
00000101: 65 72
00000102: 62 76
00000103: 20 65
00000104: 53 72
00000105: 65 0A
00000106: 72 65
00000107: 76 78
00000108: 65 70
00000109: 72 6F
0000010A: 0D 72
0000010B: 0A 74
0000010C: 65 20
0000010D: 78 44
0000010E: 70 49
0000010F: 6F 53
00000110: 72 50
00000111: 74 4C
00000112: 20 41
00000113: 44 59
00000114: 49 3D
00000115: 53 3A
00000116: 50 30
00000117: 4C 0A
00000118: 41 58
00000119: 59 20
0000011A: 3D 2D
0000011B: 3A 6E
0000011C: 30 6F
0000011D: 0D 63
0000011E: 0A 75
0000011F: 58 72
00000120: 20 73
00000121: 2D 6F
00000122: 6E 72
00000123: 6F 20
00000124: 63 2D
00000125: 75 73
00000126: 72 20
00000127: 73 30
00000128: 6F 20
00000129: 72 2D
0000012A: 20 64
0000012B: 2D 70
0000012C: 73 6D
0000012D: 20 73
0000012E: 30 26
0000012F: 20 0A
00000130: 2D 6D
00000131: 64 6F
00000132: 70 6E
00000133: 6D 6F
00000134: 73 20
00000135: 26 2F
00000136: 0D 75
00000137: 0A 73
00000138: 6D 62
00000139: 6F 64
0000013A: 6E 72
0000013B: 6F 69
0000013C: 20 76
0000013D: 2F 65
0000013E: 75 2F
0000013F: 73 61
00000140: 62 70
00000141: 64 70
00000142: 72 2F
00000143: 69 73
00000144: 76 74
00000145: 65 61
00000146: 2F 72
00000147: 61 74
00000148: 70 2E
00000149: 70 65
0000014A: 2F 78
0000014B: 73 65
0000014C: 74 26
0000014D: 61 0A
FC: start-NotWorking.sh longer than START-WORKING.SH

1 Answers1

2

One is probably written in DOS format, where line endings are carriagereturn+newline, whereas Unix format is just one newline character. The shell doesn't understand the carriagereturn and sees that as just another character such as a letter or dot. Hence you get errors.

Using Notepad++ (a Windows program) will probably ignore the different line endings. If you really want to see the differences use

cmp -l file1 file2

This will compare each byte, outputting differing byte values in octal.

You can also compare the output of

cat -vet file1

and

cat -vet file2

carriagereturn is shown as ^M, tabs as ^I. End of line is $.

Edit: your FC output shows the bytes as hexadecimal. 0D is the carriagereturn, 0A is newline.

To convert from DOS to Unix format, you can use the dos2unix command (you may need to install the dos2unix package first).

dos2unix -o file1
wurtel
  • 1,537