[clug] Pointless time-wasting bash questions

Scott Ferguson scott.ferguson.clug at gmail.com
Thu Jun 25 22:00:03 MDT 2015


You win 1 internets


On 26/06/15 10:14, Bob Edwards wrote:
> On 26/06/15 10:06, Bob Edwards wrote:
>> On 26/06/15 09:57, Bob Edwards wrote:
>>> On 25/06/15 22:15, Scott Ferguson wrote:
>>>> On 25/06/15 21:44, Eyal Lebedinsky wrote:
>>>>> On 25/06/15 19:29, Scott Ferguson wrote:
>>>>>> Messing with bracket contractions.
<snipped>

>>>>
>>>> Both people are adamant only cp and bash builtins were allowed. I tried
>>>> xargs anyway because it's been bugging me for days, but couldn't work
>>>> out how to solve it that way either.
>>>>
>>>
>>> I could argue that this is "one command", using only bash builtins
>>> and cp:
>>>
>>> for i in .pm /GenericAgent.pm ; do cp Kernel/Config${i}.dist
>>> Kernel/Config${i} ; done

It does use only cp and bash builtins - and it *works*.
And yes, you could 'argue' it's a single command, and you'd win the
argument with me - not sure about the interviewers though (and don't
really care).

>>>
>>> Bob Edwards
>>
>> Or maybe I should have shortened it as per the initial examples:
>>
>> for i in /GenericAgent.pm .pm ; do cp Kernel/Config${i}{.dist,} ; done
>>
>> Bob Edwards.
>>
> 
> Or why not save typing a couple extra chars:
> 
> for i in /GenericAgent. . ; do cp Kernel/Config${i}pm{.dist,} ; done
> 
> (getting harder to read, though).

I like that! It's more of a thought exercise than an effort to produce
portable, easy to read and maintain code though.

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

I fiddled with read, !#, and arrays as a possible alternative to loops.
Admittedly my bash knowledge is very much less than basic.
I'm told bash is simple, but... if that was the case I'd be ideally
suited to mastering it :)


> 
> Bob Edwards
> 
<snipped>

For the time being I'll attempt to avoid wasting more time on the puzzle
every-time I come across an instance where I multiple cp and renaming of
files from different directories (with different file names). If I
really need to hurt my head I can always spaghetti wrestle perl.

Thanks, and Kind regards



More information about the linux mailing list