Difference between revisions of "OPS435 Lecture 6 - Bash"

From CDOT Wiki
Jump to: navigation, search
(Created page with 'Today we looked at funtictions in bash. TLDP has a [http://tldp.org/LDP/abs/html/functions.html nice tutorial].')
 
m (Andrew moved page OPS435 Lecture 6 to OPS435 Lecture 6 - Bash)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
Today we looked at funtictions in bash. TLDP has a [http://tldp.org/LDP/abs/html/functions.html nice tutorial].
 
Today we looked at funtictions in bash. TLDP has a [http://tldp.org/LDP/abs/html/functions.html nice tutorial].
 +
 +
In-class example:
 +
 +
<source lang="bash">#!/bin/bash
 +
 +
printServiceStatus()
 +
{
 +
  if status $1 2>/dev/null | grep 'start/running' > /dev/null
 +
  then
 +
    echo "The service is running"
 +
  else
 +
    echo "The service is not running"
 +
  fi
 +
}
 +
 +
echo -n "Please enter service name:"
 +
read SERVICENAME
 +
 +
printServiceStatus $SERVICENAME</source>

Latest revision as of 12:41, 22 August 2017

Today we looked at funtictions in bash. TLDP has a nice tutorial.

In-class example:

#!/bin/bash

printServiceStatus()
{
  if status $1 2>/dev/null | grep 'start/running' > /dev/null
  then
    echo "The service is running"
  else
    echo "The service is not running"
  fi
}

echo -n "Please enter service name:"
read SERVICENAME

printServiceStatus $SERVICENAME