[clug] Pointless time-wasting bash questions

Eyal Lebedinsky eyal at eyal.emu.id.au
Thu Jun 25 05:44:09 MDT 2015

On 25/06/15 19:29, Scott Ferguson wrote:
> Messing with bracket contractions.
> *1*.
> cp Kernel/Config/GenericAgent.pm.dist Kernel/Config/GenericAgent.pm
> I can shorten the process with:-
> cp Kernel/Config/GenericAgent.pm{.dist,}
> *2*. likewise
> cp Kernel/Config.pm.dist Kernel/Config.pm
> I can shorten the process with:-
> cp Kernel/Config.pm{.dist,}
> *3*. I can combine the two with:-
> cp Kernel{/Config,/Config/GenericAgent}.pm{.dist,}

Really? cp with four arguments does what when the last one is not a directory?

As you show on the next line, this yields
cp Kernel/Config.pm.dist Kernel/Config.pm Kernel/Config/GenericAgent.pm.dist Kernel/Config/GenericAgent.pm

(the line break in the echo is only for show).

> e.g.:-
> echo Kernel{/Config,/Config/GenericAgent}.pm{.dist,}
> Kernel/Config.pm.dist Kernel/Config.pm
> Kernel/Config/GenericAgent.pm.dist Kernel/Config/GenericAgent.pm
> Anyone know a more ergonomic process?
> (extra points if it's easier to read)
> Any dangers I may have overlooked?

Well, in general, and expansion (meaning not an explicit list) hides the
possibility of unexpected results...

> Disclaimer: it 'might' not really a pointless exercise (but it's a way
> of putting off less interesting work) as I've a similar task that could
> use variables in place of "/Config" and ".dist" to deal with a wider
> range of directory names and file extensions.
> Kind regards


Eyal Lebedinsky (eyal at eyal.emu.id.au)

More information about the linux mailing list