[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: exec, redirections and variable expansions

From: Chet Ramey
Subject: Re: exec, redirections and variable expansions
Date: Tue, 26 Jan 2010 11:04:59 -0500
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv: Gecko/20100111 Thunderbird/3.0.1

On 1/25/10 8:32 AM, mike bakhterev wrote:

> Bash Version: 4.0
> Patch Level: 35
> Release Status: release
> Description:
>       Something is wrong with variable substitution in the exec invocation.
>       When i try to close file descriptor whose number is in variable X with
>       command:
>               exec $X>&-
>       Bash reports:
>                exec: NUMBER: not found

The file descriptor number must be a decimal number specifying the fd to
close; it cannot be a word and is not subject to expansion.  If you use
`eval', you will get the results you want.

Bash-4.1 introduces a new redirection syntax that does what you want:

        exec {X}>&-


``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]