scripting:basics

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
scripting:basics [2015/08/02 04:27]
bill_thomson
scripting:basics [2015/08/02 04:31]
bill_thomson
Line 148: Line 148:
  
 ==== Block commenting ==== ==== Block commenting ====
-To temporarily disable complete blocks of code you would normally have to prefix every line of that block with a # (hashmark) to make it a comment. There'​s a little trick, using the pseudo command '':''​ (colon) and input redirection. The '':''​ does nothing, it's a pseudo command, so it does not care about standard input. In the following code example, you want to test only the things that don't harm (mail, logging) ​but not actually do anything to the system (dump database, shutdown):+To temporarily disable complete blocks of code you would normally have to prefix every line of that block with a # (hashmark) to make it a comment. There'​s a little trick, using the pseudo command '':''​ (colon) and input redirection. The '':''​ does nothing, it's a pseudo command, so it does not care about standard input. In the following code example, you want to test mail and logging, but not dump the database, ​or execute a shutdown:
 <code bash> <code bash>
 #!/bin/bash #!/bin/bash
Line 165: Line 165:
 </​code>​ </​code>​
 What happened? The '':''​ pseudo command was given some input by redirection (a here-document) - the pseudo command didn't care about it, effectively,​ the entire block was ignored. What happened? The '':''​ pseudo command was given some input by redirection (a here-document) - the pseudo command didn't care about it, effectively,​ the entire block was ignored.
-One could say, **the whole block is a comment**. For completeness:​ To make the here-document possible, the shell might generate a temporary file in the ''/​tmp''​ directory. 
  
 The here-document-tag was quoted here **to avoid substitutions** in the "​commented"​ text! Check [[syntax:​redirection#​tag_heredoc | redirection with here-documents]] for more The here-document-tag was quoted here **to avoid substitutions** in the "​commented"​ text! Check [[syntax:​redirection#​tag_heredoc | redirection with here-documents]] for more
  • scripting/basics.txt
  • Last modified: 2019/08/30 09:07
  • by ersen