Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

How to define "check_err" function

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
satimis
Posts: 536
Joined: 2004-09-11 11:50
Location: Hong Kong

How to define "check_err" function

#1 Post by satimis »

Hi folks,

I have following simple script

Code: Select all

#! /bin/sh

LOGFILE=/tmp/log.$$
export LFS=/mnt/lfs
# No need to check this for errors
mount /dev/hda6 /mnt/lfs | tee $LOGFILE
check_err $? $LOGFILE
mkdir -p $LFS | tee $LOGFILE
check_err $? $LOGFILE
/usr/sbin/chroot "$LFS" /usr/bin/env -i HOME=/root \
TERM="$TERM"PS1='\u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin /bin/bash --login +h | tee $LOGFILE
#
check_err()
#
check_err $? $LOGFILE
{
  if [ -s $2 ]; then
    echo "The previous command caused output. Do you want to continue?"
    read ans
    if [ "$ans" == "no" ] || [ "$ans" == "NO" ] || [ "$ans" == "n" ] || [ "$ans" == "N" ]; then
      echo "Okay... bailing"
      exit 1
    fi
  fi
  if [ "$1" -eq "0" ]; then
    echo "Command was succesful with no output... continuing"
    return
  else
    echo "Error : $1"
    exit $1
  fi
}  
Could you please shed me some light to define "check_err ()" function.

TIA

B.R.
satimis

lacek
Posts: 764
Joined: 2004-03-11 18:49
Location: Budapest, Hungary
Contact:

#2 Post by lacek »

This is the way to define shell functions:

Code: Select all

#!/bin/bash

check_err() {
    echo parameter1: $1
    echo parameter2: $2
}

check_err "suhajj" "aha"

Post Reply