Subject: RE: [hackers-il] enhancing the 'Unix IDE'

From: Omer Musaev <[email-masked]>
Date: Thu, 29 Apr 2004 11:48:55 +0300

My $0.02

Shortly before I had switched to Python for scripting:

-------------------- cut here --------------------

# -*- sh-mode -*- 

#
# echoes output
common::echo() {
	echo "$*"
}

#
# echoes output without trailing carriage return
common::necho() {
	printf "$*"			
}

#
#
#  ask: receives prompt. 
#  returns user answer
common::ask( ) {  
  local prompt="${1}"
  local ans
  if [  -z "${prompt}" ] 
  then
     prompt="Enter yes or no" 
  else 
     prompt="${prompt} [y|n] "
  fi

  ans=
  while [ -z "${ans}" ] ; do
     common::necho "$prompt " 
     read ans 
     case $ans in 
        y*|Y*)
           return 0 
        ;;
        n*|N*)
           return 1 
        ;;
        *)
           ans=
           common::echo "Invalid input"
        ;;
     esac
  done
}

#
# 
# quetly: execute rest of command line without output
common::quetly() {  
  eval "$* 1>/dev/null 2>&1"
}

#
#
# undefined:  at least one of arguments has no value
common::undefined() {  
  local ans=
  local var=
  for var in $*
  do
     local var_val
     eval "var_val=\$$var"
     [ -z "${var_val}" ] && ans=1
  done
  [ -n "${ans}" ] && return 0
  return 1
} 

#
#  defined
#  at least one of arguments has a value
common::defined() {  
  local ans=
  local var=
  for var in $*
  do
     local var_val
     eval "var_val=\$$var"
     [ -z "${var_val}"  ]  && ans=1
  done
  [ -z "${ans}" ] && return 0
  return 1
}

-------------------- cut here --------------------

HTH

--
 o.m.

________________________________________________________________________
This email has been scanned for all viruses. 

Mercury Interactive Corporation
Optimizing Business Processes to Maximize Business Results

---

From: Tzafrir Cohen <[email-masked]>
Date: Thu, 29 Apr 2004 16:32:16 +0300

Some petty notes:

Usually it is better to use "$@" instead of "$*" :

> -------------------- cut here --------------------

Here it doesn't really matter
> # echoes output without trailing carriage return

Here "$*" should indeed be used

>   eval "$* 1>/dev/null 2>&1"

Why not simply:

  "$@" &>/dev/null

> # undefined:  at least one of arguments has no value

Here you would theoretically "$@" (with the quotes), but variable names
should not contain space, anyway.

-- 
Tzafrir Cohen                       +---------------------------+
http://www.technion.ac.il/~tzafrir/ |vim is a mutt's best friend|
mailto:[email-masked]       +---------------------------+

---

From: Gabor Szabo <[email-masked]>
Date: Thu, 29 Apr 2004 21:51:06 -0200 (GMT+2)

> Shortly before I had switched to Python for scripting:

why not show us some of your python code too ?

Gabor