Difference between revisions of "Sh"

From Secure Computing Wiki
Jump to: navigation, search
m (Reverted edits by Exyhypele (talk) to last revision by 74.95.66.25)
 
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:
  
&lt;pre>#!/bin/sh
+
<pre>#!/bin/sh
 
echo "I live in `dirname $0`"
 
echo "I live in `dirname $0`"
  
Line 16: Line 8:
 
cd /
 
cd /
 
sh ~/test.sh
 
sh ~/test.sh
&lt;/pre>
+
</pre>
  
 
== Special Variable ==
 
== Special Variable ==
&lt;pre>Variable ==> Meaning
+
<pre>Variable ==> Meaning
 
------------------------------
 
------------------------------
 
$0 ==> Name of script
 
$0 ==> Name of script
Line 34: Line 26:
 
$- ==> 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&lt;/pre>
+
$! ==> Process ID (PID) of last job run in background</pre>

Latest revision as of 16:47, 26 November 2010

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

#!/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

Special Variable

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