From owner-freebsd-questions Thu Nov 21 1:42:46 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D730637B401 for ; Thu, 21 Nov 2002 01:42:44 -0800 (PST) Received: from bellavista.cz (mail.bellavista.cz [62.168.44.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0FA5143E8A for ; Thu, 21 Nov 2002 01:42:41 -0800 (PST) (envelope-from neuhauser@bellavista.cz) Received: from freepuppy.bellavista.cz ([10.1.0.1]) by bellavista.cz (8.9.3/8.9.8) with ESMTP id KAA31774 for ; Thu, 21 Nov 2002 10:42:19 +0100 Received: by freepuppy.bellavista.cz (Postfix, from userid 1001) id 3C1252FDAB2; Thu, 21 Nov 2002 10:41:13 +0100 (CET) Date: Thu, 21 Nov 2002 10:41:13 +0100 From: Roman Neuhauser To: FreeBSD Questions List Subject: Re: Bash programming; Was: connecting to SCSI drive Message-ID: <20021121094112.GR77198@freepuppy.bellavista.cz> Mail-Followup-To: FreeBSD Questions List References: <20021120180314.GA564@sten.alder.net> <20021120182423.GB30909@dan.emsphone.com> <3DDBE4A9.5060708@mac.com> <20021120204738.GA949@sten.alder.net> <20021121071713.GA2641@sten.alder.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20021121071713.GA2641@sten.alder.net> User-Agent: Mutt/1.5.1i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG # rjhalljr@starpower.net / 2002-11-21 02:17:13 -0500: > Following the suggestions that were posted, I now have a working > script that checks for a connection to the DVD-RAM drive. The > following works, but returns the 'Device not configured' error > if there's no disk in the drive. > > elif !(sudo mount -t ufs -o rw /dev/cd0a $montering_punkt) > then > > Currently, I'm suppressing the error message (2>/dev/null), but I'd > rather capture sterr in a variable and replace it with a custom > message if the error is 'Device not configured'. (The devise is > configured, but I forgot to put a disk in the drive, so the system > error message is confusing.) I've tried read and redirection, but I > can't seem to capture the error message in a variable. Does > anyone know how to do this? tested in zsh (should work in bash): MSG=$(sudo mount ... 2>&1) if [ $? -ne 0 -a $MSG == "Device not configured" ]; then echo "My custom error message" fi a dumbed-down version that'll work in /bin/sh (most portable): MSG=`sudo mount /floppy 2>&1` if [ $? -ne 0 -a "x$MSG" = "xDevice not configured" ]; then echo "My custom error message." fi -- If you cc me or remove the list(s) completely I'll most likely ignore your message. see http://www.eyrie.org./~eagle/faqs/questions.html To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message