scripting:newbie_traps

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
scripting:newbie_traps [2016/05/11 13:19]
stephenwb Added section about return value vs. output
scripting:newbie_traps [2020/05/28 12:34]
fgrose [Exporting] clarify English
Line 155: Line 155:
 ==== Exporting ==== ==== Exporting ====
  
-Exporting a variable means to give **newly created** (child-)processes a copy of that variable. **not** copy a variable created in a child process to the parent process. The following example does **not** work, since the variable ''​hello''​ is set in a child process (the process you execute to start that script ''​./​script.sh''​):​+Exporting a variable means giving ​**newly created** (child-)processes a copy of that variable. ​ It does **not** copy a variable created in a child process ​back to the parent process. The following example does **not** work, since the variable ''​hello''​ is set in a child process (the process you execute to start that script ''​./​script.sh''​):​
  
 <​code>​ <​code>​
Line 166: Line 166:
 </​code>​ </​code>​
  
-Exporting is one-way. The direction is parent process to child process, not the reverse. The above example **will** work, when you don't execute the script, but include ("​source"​) it:+Exporting is one-way. The direction is from parent process to child process, not the reverse. The above example **will** work, when you don't execute the script, but include ("​source"​) it:
 <​code>​ <​code>​
 $ source ./script.sh $ source ./script.sh
Line 186: Line 186:
 grep ^root: /etc/passwd >/​dev/​null 2>&1 grep ^root: /etc/passwd >/​dev/​null 2>&1
  
-if [ $? -neq 0 ]; then+if [ $? -ne 0 ]; then
   echo "root was not found - check the pub at the corner"​   echo "root was not found - check the pub at the corner"​
 fi fi
  • scripting/newbie_traps.txt
  • Last modified: 2020/05/28 12:34
  • by fgrose