Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 Sep 2002 11:30:09 -0700 (PDT)
From:      =?ISO-8859-1?Q?Mikko_Ty=F6l=E4j=E4rvi?= <mbsd@pacbell.net>
To:        Jimmy Lantz <jimmy.lantz@lusidor.com>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: Bourne shell redirection of STDOUT
Message-ID:  <20020928112417.K97357-100000@atlas.home>
In-Reply-To: <5.1.0.14.0.20020928170713.00bcc758@mail.lusidor.nu>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020928112417.K97357-100000>