How to define "check_err" function

Need help with C, C++, perl, python, etc?

How to define "check_err" function

Postby satimis » 2005-08-15 14:44

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
satimis
 
Posts: 524
Joined: 2004-09-11 11:50
Location: Hong Kong

Postby lacek » 2005-08-16 11:19

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"
lacek
Moderator Team Member
 
Posts: 769
Joined: 2004-03-11 18:49
Location: Budapest, Hungary


Return to Programming

Who is online

Users browsing this forum: No registered users and 6 guests

fashionable