Re: glob pattern and redirected input file name

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

 



On Thu, Aug 29, 2013 at 04:49:12PM -0700, Jack Bates wrote:
> What is DASH supposed to do when input is redirected from a file,
> and the file name is a glob pattern? e.g.

>    tar xz < foo-*.tar.gz

> Is it supposed to expand the glob pattern, or is that not supported?

Per POSIX XCU 2.7 Redirection, pathname generation may (but need not) be
performed on the word after a redirection operator other than << or <<-
if the shell is interactive and one word would result.

Dash chooses the option that results in the smallest code: never
performing pathname generation in this case.

> The following both work, is there a better workaround?

>    tar fxz foo-*.tar.gz

>    tar xz < $(echo foo-*.tar.gz)

These are both concise methods. The former's problem is that it does
something strange if more than one file matches. The second has problems
with pathnames starting with '-', containing backslashes or ending with
newlines.

In a script you might do
    set -- foo-*.tar.gz
    if [ "$#" -ne 1 ] || [ ! -f "$1" ]; then
        echo "Bad wildcard"
        exit 2
    fi
    tar -xzf "$1"

-- 
Jilles Tjoelker
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux