From owner-freebsd-questions Sat Sep 28 11:30:11 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 AC3CC37B401 for ; Sat, 28 Sep 2002 11:30:09 -0700 (PDT) Received: from mta7.pltn13.pbi.net (mta7.pltn13.pbi.net [64.164.98.8]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5FB3143E42 for ; Sat, 28 Sep 2002 11:30:09 -0700 (PDT) (envelope-from mbsd@pacbell.net) Received: from atlas ([64.168.24.134]) by mta7.pltn13.pbi.net (iPlanet Messaging Server 5.1 (built May 7 2001)) with ESMTP id <0H35003ESVE8CP@mta7.pltn13.pbi.net> for freebsd-questions@FreeBSD.ORG; Sat, 28 Sep 2002 11:30:09 -0700 (PDT) Date: Sat, 28 Sep 2002 11:30:09 -0700 (PDT) From: =?ISO-8859-1?Q?Mikko_Ty=F6l=E4j=E4rvi?= Subject: Re: Bourne shell redirection of STDOUT In-reply-to: <5.1.0.14.0.20020928170713.00bcc758@mail.lusidor.nu> X-X-Sender: mikko@atlas.home To: Jimmy Lantz Cc: freebsd-questions@FreeBSD.ORG Message-id: <20020928112417.K97357-100000@atlas.home> MIME-version: 1.0 Content-type: TEXT/PLAIN; charset=US-ASCII Content-transfer-encoding: 7BIT 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 On Sat, 28 Sep 2002, Jimmy Lantz wrote: > Hi, > I wonder if anyone know a way to redirect the STDOUT directly to a variabel > in a shellscript w/o using tempfile. Use backticks ``. > > I know I can use a tempfile but I'm looking for a way to avoid using a file. > > in other words > > Does anyone have an alternative to this? I would like to be able to run > this script read-only : > #!/bin/sh > DIALOG=${DIALOG=/usr/bin/dialog} > dialog --inputbox "Hitme" 8 40 \ > 2> /tmp/tempfile > myvar=`cat /tmp/tempfile` Aha. You're not redirecting stdout, you want stderr, and backticks will only get stdout (which you don't want, as it is used to present the dialog). Here are two possible solutions: 1) Swap stdout and stderr: myvar=`$DIALOG --inputbox "Hitme" 8 40 9>&1 1>&2 2>&9` 2) Since dialog will require a tty anyway, let it talk directly to /dev/tty, and redirect stderr to stdout: myvar=`$DIALOG --inputbox "Hitme" 8 40 2>&1 >/dev/tty` $.02, /Mikko To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message