Line Breaks in Various Operating Systems
- Windows uses CRLF (\r\n, 0D 0A)
- Mac uses CR (\r, 0D)
- Linux uses LF (\n, 0A)
The Issue - Text scripts may be moved from one OS to another and not be understood by the OS although the
text itself looks fine.
The file on hoare.cs.umsl.edu
>od -x .bash_profile
0000000 2023 622e 7361 5f68 7270 666f 6c69 0a65
0000020 230a 4720 7465 7420 6568 6120 696c 7361
0000040 7365 6120 646e 6620 6e75 7463 6f69 736e
0000060 690a 2066 205b 662d 7e20 2e2f 6162 6873
0000100 6372 5d20 203b 6874 6e65 090a 202e 2f7e
0000120 622e 7361 7268 0a63 6966 0a0a 2023 7355
0000140 7265 7320 6570 6963 6966 2063 6e65 6976
0000160 6f72 6d6e 6e65 2074 6e61 2064 7473 7261
0000200 7574 2070 7270 676f 6172 736d 0a0a 4150
0000220 4854 243d 4150 4854 243a 4f48 454d 2e2f
0000240 6f6c 6163 2f6c 6962 3a6e 4824 4d4f 2f45
0000260 6962 0a6e 650a 7078 726f 2074 4150 4854
0000300 000a
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
An ftp and a copy and paste:
A Java Approach - The Code
ublic class writelines {
public static void main(String args[]){
StringBuffer sbf = new StringBuffer("This is the first line.");
sbf.append(System.getProperty("line.separator"));
sbf.append("This is second line.");
System.out.println(sbf);
}
}
The Run
This is the first line.
This is second line.
writelines.java on hoare.cs.umsl.edu
~/javafiles >java writelines |od -x
0000000 6854 7369 6920 2073 6874 2065 6966 7372
0000020 2074 696c 656e 0a2e 6854 7369 6920 2073
0000040 6573 6f63 646e 6c20 6e69 2e65 000a
0000055
~/javafiles >
writelines.java on Windows
C:\MyCourse\CS4010>java writelines |od -x
0000000 6854 7369 6920 2073 6874 2065 6966 7372
0000020 2074 696c 656e 0d2e 540a 6968 2073 7369
0000040 7320 6365 6e6f 2064 696c 656e 0d2e 000a
0000057
C:\MyCourse\CS4010>
~/javafiles >