[clug] Pointless time-wasting bash questions

Bob Edwards Robert.Edwards at anu.edu.au
Thu Jun 25 23:26:20 MDT 2015

On 26/06/15 15:06, Paul Harvey wrote:
> On 26 Jun 2015 15:00, "Scott Ferguson" <scott.ferguson.clug at gmail.com>
> wrote:
>> On 26/06/15 14:21, Paul Harvey wrote:
>>>> If I was to use it for real work I'd "eval ''". e.g.:-
>>>> for i in /GenericAgent. . ; do eval cp 'Kernel/Config${i}pm{.dist,}' ;
> done
>>> Is the eval necessary?
>> If the code is used for shortening file names in various directories -
>> and there is the possibility those names contains spaces. Then it would
>> 'seem' necessary.
> I used to use eval for this too, but forced myself to rewrite them without.
> I'm pretty sure something like:
> for i in /GenericAgent. . ; do cp "Kernel/Config${i}pm"{.dist,} ; done
> Would do the same thing, safely, without eval.
> I'll test it later when I'm back in front of a computer

Perhaps, also, you need to show how you are going to introduce a
filename with spaces in it into the "for i" word list?

In the example above, the quotes add nothing but noise unless you
also change the wordlist to include names with spaces etc.

I think we need to acknowledge that bash is a shell and in shell
a space is a delimiter.

If you want to use something else as your delimiter, maybe a shell
is not the right tool for the job?

Using eval and/or seemingly random placement of quotes is not very
easy for a code auditor etc. to reliably check.

On the other hand, a shell script writer should always ensure that
their script behaves "nicely" if it does encounter a filename with
spaces etc. in it.


Bob Edwards.

More information about the linux mailing list