<!DOCTYPE html> <html>
<head> <link rel="stylesheet" href="index.css" type="text/css" media="screen" /> <script src="jquery-1.6.min.js" type="text/javascript"></script> <script src="../dist/jquery.syntax.js" type="text/javascript"></script> <script src="../dist/jquery.syntax.cache.js" type="text/javascript"></script> <script type="text/javascript"> jQuery(function($) { $.syntax(); }); </script> </head> <body> <h1>Syntax: Bash</h1> <p>Bash is context-sensitive - a script could mean different things depending on what is defined in the environment. Thus, to present Bash code clearly, you will need to use inline markup, such as the last example on this page.</p> <pre><code class="syntax language-bash-script">#!/bin/bash
# Counting to 11 in 10 different ways.
n=1; echo -n "$n "
let "n = $n + 1" # let "n = n + 1" also works. echo -n "$n "
: $((n = $n + 1)) # ":" necessary because otherwise Bash attempts + to interpret "$((n = $n + 1))" as a command. echo -n "$n "
(( n = n + 1 )) # A simpler alternative to the method above. # Thanks, David Lombard, for pointing this out. echo -n "$n "
n=$(($n + 1)) echo -n "$n "
: $[ n = $n + 1 ] # ":" necessary because otherwise Bash attempts + to interpret "$[ n = $n + 1 ]" as a command. # Works even if "n" was initialized as a string. echo -n "$n "
n=$[ $n + 1 ] # Works even if "n" was initialized as a string. * Avoid this type of construct, since it is obsolete and nonportable. # Thanks, Stephane Chazelas. echo -n "$n "
# Now for C-style increment operators. # Thanks, Frank Wang, for pointing this out.
let "n++" # let "++n" also works. echo -n "$n "
(( n++ )) # (( ++n ) also works. echo -n "$n "
: $(( n++ )) # : $(( ++n )) also works. echo -n "$n "
: $[ n++ ] # : $[ ++n ]] also works echo -n "$n "
echo
exit 0</code></pre>
<p>
<pre><code class=“syntax bash-script”>#!/bin/bash
svc_cluster_ip=10.0.0.10 svc_priv_dsa=~/.ssh/id_dsa
if [ ! -f $svc_priv_dsa ] ; then
echo " ${0##*/} is missing the SSH DSA private key" echo " needed to access the SAN Volume controller." echo " Please specify the correct path!"
fi
if [ -z $1 ] ; then
echo echo " ${0##*/} [ WWPN ]" echo echo " WWPN - WWPN, or part of WWPN that is being searched." echo " Should be entered in continous format (ie. no dash (-) or colon (:))!" echo exit 1;
fi
WWPN=$1
list_wwpn_by_host() {
local _host=$1 if [ ! -z $_host ] ; then ssh -i $svc_priv_dsa admin@$svc_cluster_ip svcinfo lshost \ -delim : $_host | grep ^WWPN | sed "s,WWPN:,," fi
}
set -x
HOST_LIST="$( ssh -i $svc_priv_dsa admin@$svc_cluster_ip svcinfo lshost -delim : -nohdr | cut -d: -f2 )"
for HOST in $HOST_LIST; do
echo -n "$HOST: " echo `list_wwpn_by_host $HOST`
done | grep $WWPN
set +x </code></pre>
<p>This next example uses inline HTML to markup and highlight <code class=“syntax bash-script”>rd-resolve-test bob</code>.</p>
<pre id=“ex2”><code class=“syntax brush-bash”>samuel@ayako:~$ which git /usr/bin/git samuel@ayako:~$ ls -lah getconf getent getopt getopts gettext gettext.sh gettextize
samuel@ayako:~# sudo <span class=“highlight”><span class=“function”>rd-resolve-test</span> bob</span> /home/samuel</code></pre>
<p>Here is the HTML of the above <code class=“syntax html”><pre></code>:</p>
<pre id=“ex2_html” class=“syntax html”></pre>
<script type=“text/javascript”>
$('#ex2_html').text($('<div>').append($('#ex2').clone()).html());
</script>
</body>
</html>