pavement

Escaped to multi-line format

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
 
Line 1: Line 1:
An often-followed convention when reproducing shell scripts online is "escaping" very long lines, using the backslash character, into multiple lines for readability.  For example, the following simple script, which concatenates a lot of files into one file named "all.files":
+
An often-followed convention when reproducing shell scripts online is "escaping" carriage returns, using the backslash character, in order to render single very long continous lines into multiple lines for readability.  For example, the following simple script, which concatenates a lot of files into one file named "all.files":
  
 
  #!/bin/sh
 
  #!/bin/sh
Line 12: Line 12:
 
  > all.files
 
  > all.files
  
On most machines, the script should work exactly the same in escaped format as it does in the normal, unescaped format.  However, I tend to recommend removing the backslashes and carriage returns and entering lines expressed this way as single continous lines, when actually entering in scripts - because while anything ''should'' work fine escaped, I have very occasionally seen source code that refused to work in escaped format but did work once the escapes were removed and the lines concatenated.  So if you don't escape to multiple lines, you have one less thing to worry about potentially having to fix.
+
On most machines, the script should work exactly the same in escaped format as it does in the normal, unescaped format.  However, I tend to recommend removing the backslashes and carriage returns and entering lines expressed this way as single continous lines - because while anything ''should'' work fine escaped, I have very occasionally seen source code that refused to work in escaped format but did work once the escapes were removed and the lines concatenated.  So if you don't escape to multiple lines, you have one less thing to worry about potentially having to fix.
  
 
[[Category:FreeBSD Terminology]]
 
[[Category:FreeBSD Terminology]]

Revision as of 16:36, 14 December 2004

An often-followed convention when reproducing shell scripts online is "escaping" carriage returns, using the backslash character, in order to render single very long continous lines into multiple lines for readability. For example, the following simple script, which concatenates a lot of files into one file named "all.files":

#!/bin/sh
cat one.file two.file three.file four.file five.file six.file seven.file eight.file > all.files

Could be rendered like this:

#!/bin/sh
cat one.file two.file three.file \
four.file five.file six.file \
seven.file eight.file \
> all.files

On most machines, the script should work exactly the same in escaped format as it does in the normal, unescaped format. However, I tend to recommend removing the backslashes and carriage returns and entering lines expressed this way as single continous lines - because while anything should work fine escaped, I have very occasionally seen source code that refused to work in escaped format but did work once the escapes were removed and the lines concatenated. So if you don't escape to multiple lines, you have one less thing to worry about potentially having to fix.

Personal tools