[Nottingham] Re: Quick! I need a bash one liner!

James Gibbon jg at jamesgibbon.com
Wed Feb 2 12:49:14 GMT 2005


On Wed, 2 Feb 2005 08:53:16 +0000
Michael Erskine <msemtd at yahoo.co.uk> wrote:

> On Tuesday 01 February 2005 21:37, Johannes Kling wrote:
> > > for file in *.[ch]; do expand -t 4 $file > t1; mv t1 $file; done
> >
> > Isn't that just your original script re-written using ';' instad of
> > newlines? I.e. No more of a one-liner than:
> 
> Yes...
> 
> What I mean by "one-liner" is being able to issue the commands at the
> prompt  rather than written in a file.

Well, for what it's worth - you don't need to use ; in place of
newlines to do that, you can use the return key with impunity :D

eg:

dino:~/photos/helsinki> for i in * ; do
> sum $i
> done
01111   351
48141   360
59782   442
61217   378
05158   396
29670   386
37572   366
19830   357
48728   362
dino:~/photos/helsinki> 

In BASH, the whole thing will be preserved as a one-liner in your
command history like this:

for i in * ; do sum $i; done

.. so you can repeat the whole thing using ^P or the up cursor
key.






More information about the Nottingham mailing list