Shell script help

Colin Law clanlaw at gmail.com
Thu Oct 16 12:05:23 UTC 2014


On 16 October 2014 10:04, Nils Kassube <kassube at gmx.net> wrote:
> Colin Law wrote:
>> On 16 October 2014 08:01, Nils Kassube <kassube at gmx.net> wrote:
>> > Colin Law wrote:
>> >> To clarify, a script called, for example, using something like
>> >> myscript "the path*"    note the trailing *
>> >>
>> >> and in myscript something like
>> >>
>> >> for f in /a/b/"$1"/*.txt
>> >> where this is to be interpreted as
>> >> for f in /a/b/the\ path*/*.txt
>> >
>> > You could set IFS to "\n\t" [1] to eliminate the problem of spaces
>> > in
>> > the filename an then omit the quotes around "$1" - something like
>> > this:
>> >
>> > IFS="$(printf '\n\t')"
>> > for f in /a/b/$1/*.txt
>> >
>> > But I'm not sure if that would be safe with arbitrary directory
>> > names.
>> Excellent idea.  It is only for private use for a particular purpose,
>> and in fact will generally be called from another script, so no
>> worries about the script being used with malicious intent.
>
> Actually I didn't think of malicious intent but more something like
> directory names with charcters that could be interpreted by the shell.
> Something like my music collection where directories are used for artist
> names including some names with "&".

Ah yes, good point.  In fact I have got around the problem in a way
that means I don't need the wildcard in the parameter, which is a
better solution I think.

Many thanks

Colin




More information about the ubuntu-users mailing list