bug-bash
[Top][All Lists]
Advanced

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

Re: Encoding multiple filenames in a single variable


From: Chris F.A. Johnson
Subject: Re: Encoding multiple filenames in a single variable
Date: Sun, 29 Aug 2010 04:07:23 -0400 (EDT)
User-agent: Alpine 2.00 (LMD 1167 2008-08-23)

On Sun, 29 Aug 2010, Jon Seymour wrote:

This isn't strictly a bash question, and I'd prefer a POSIX-only
solution if possible [ suggestions as to a good question to ask
POSIX-only questions would be appreciated ].

  The comp.unix.shell newsgroup is a good place.

Suppose I need to encode a list of filenames in a variable and each
filename may contain spaces, what is good way to encode such a list so
that the resulting variable is readily compose-able and decodeable? In
particular, I'd like to avoid the use of (unescaped) separators which
might themselves be used in the filename.

   Either separate them with newlines, or (non-POSIX) use an array.

## POSIX
NL='
'
files=${files:+$files$NL}$nextfile

## Array
files+=( "$nextfile" )

--
   Chris F.A. Johnson, <http://cfajohnson.com>
   Author:
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)



reply via email to

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