Changes

Jump to navigation Jump to search
1,127 bytes added ,  21:39, 22 September 2009
no edit summary
Line 19: Line 19:  
# redirect the shells stderr to null
 
# redirect the shells stderr to null
 
exec 2>/dev/null</source>
 
exec 2>/dev/null</source>
 
+
==The . (dot) Command and Subshell==
[[Category:Catching signals]][[Category:Commands]]
+
The . (dot) command is used to run shell scripts as follows:
 +
<source lang="bash">. script.sh</source>
 +
The dot command allows you to modify current shell variables. For example, create a shell script as follows called /tmp/dottest.sh:
 +
<source lang="bash">#!/bin/bash
 +
echo "In script before : $WWWJAIL"
 +
WWWJAIL=/apache.jail
 +
echo "In script after : $WWWJAIL"</source>
 +
Close and save the file. Run it as follows:
 +
<source lang="bash">chmod +x /tmp/dottest.sh</source>
 +
Now, define a variable called WWWJAIL at a shell prompt:
 +
<source lang="bash">WWWJAIL=/foobar
 +
echo $WWWJAIL</source>
 +
Sample outputs:
 +
<pre>/foobar</pre>
 +
Run the script:
 +
<source lang="bash">/tmp/dottest.sh</source>
 +
Check the value of WWWJAIL:
 +
<source lang="bash">echo $WWWJAIL</source>
 +
You should see the orignal value of $WWWJAIL (/foobar) as the shell script was executed in a subshell. Now, try the dot command:
 +
<source lang="bash"> . /tmp/dottest.sh
 +
echo $WWWJAIL</source>
 +
Sample outputs:
 +
<pre>/apache.jail</pre>
 +
The value of $WWWJAIL (/apache.jail) was changed as the script was run in the current shell using the dot command.[[Category:Catching signals]][[Category:Commands]]

Navigation menu