[RndTbl] bash expansion question
Sean Walberg
sean at ertw.com
Wed Jul 7 07:30:04 CDT 2010
[sean at sergeant:~]$ mkdir /tmp/nothing
[sean at sergeant:~]$ ls /tmp/nothing | while read A; do echo $A; done
[sean at sergeant:~]$
Also gets around nasty "argument list too long" messages and doesn't need
you to remember arcane syntax. $A is quotable if you have spaces in the
filename.
Sean
On Tue, Jul 6, 2010 at 11:07 PM, Adam Thompson <athompso at athompso.net>wrote:
> I can't find what I'm looking for in the bash(1) manpage, hoping there's an
> easy answer...
>
> I want to use a construct like
> for i in ~/path/*; do something $i && rm $i; done
>
> which works great as long as there are files in ~/path/. However, when the
> directory is empty, I get:
> rm: cannot remove `/home/athompso/path/*': No such file or directory
>
> which isn't quite what I want. The quick fix in this case is to use
> for i in ~/path/*; do [ -f $i ] && something $i && rm $i; done
>
> but once again, that strikes me as inelegant and I can't remember OR find
> the better way to do it.
>
> Anyone?
>
> Thanks,
> -Adam
>
>
> _______________________________________________
> Roundtable mailing list
> Roundtable at muug.mb.ca
> http://www.muug.mb.ca/mailman/listinfo/roundtable
>
--
Sean Walberg <sean at ertw.com> http://ertw.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.muug.mb.ca/pipermail/roundtable/attachments/20100707/eb140df5/attachment.html
More information about the Roundtable
mailing list