Sean's Musings as a Service

Sean's Musings as a Service

Bash hates people who use spaces

  • Published:
  • categories: unix
  • tags: bash, scripting, unix, linux

Ok so I have lots of files… I can’t be responsible for keeping weird characters and spaces out of all of them can I?

So what is a space using loser like me to do, well after penance, jump through hoops to make it work.

So naively expecting this to work, instead I get this crap.

sgw@terd /store/ebooks/pdfs $ for i in `ls ../*.rar`; do echo "$i"; done
../PDF
Ebook
Guide
BSD
Hacks
100
...

So contorting my leg behind my head I type this, and voila.

sgw@terd /store/ebooks/pdfs $ ls ../*.rar | while read filename; do echo "$filename"; done
../PDF Ebook Guide BSD Hacks 100 Industrial Strength Tips Tools 2008 .pdf.rar
../PDF Ebook Guide Cleaning Windows XP For Dummies 2008.rar
../PDF Ebook Guide Guide To Assembly Language Programming In Linux 2008.rar
../PDF Ebook Guide High Performance MySQL 2008.rar
../PDF Ebook Guide Illustrated TCP IP A Graphic Guide To The Protocol Suite 1999 .pdf.rar
../PDF Ebook Guide OReilly - CSS Cookbook.rar
../PDF Ebook Guide OReilly - High Performance MySQL.rar
../PDF Ebook Guide OReilly - Java Servlet and JSP Cookbook - 2008 - By Laxxuss.rar
../PDF Ebook Guide OReilly UML in a Nutshell.rar
../PDF Ebook Guide ebook - HTML - Python OReilly - Core Python.rar

So overall, not that painful, thanks interwebs!

Here was my final nasty nate-like one-liner.

sgw@terd /store/ebooks/pdfs $ ls /store/ebooks/*.rar | while read filename; do echo "$filename"; name=`basename "$filename" .rar`; echo "$name"; mkdir "$name"; cd "$name"; echo inside pwd: `pwd`; rar e -y "$filename"; cd ..; echo pwd after: `pwd`; done
/store/ebooks/PDF Ebook Guide BSD Hacks 100 Industrial Strength Tips Tools 2008 .pdf.rar
PDF Ebook Guide BSD Hacks 100 Industrial Strength Tips Tools 2008 .pdf
inside pwd: /store/ebooks/pdfs/PDF Ebook Guide BSD Hacks 100 Industrial Strength Tips Tools 2008 .pdf

RAR 3.71 Copyright (c) 1993-2007 Alexander Roshal 20 Sep 2007
Shareware version Type RAR -? for help


Extracting from /store/ebooks/PDF Ebook Guide BSD Hacks 100 Industrial Strength Tips Tools 2008 .pdf.rar

Extracting Crack.txt OK
Extracting Read Me First.txt OK
Extracting Checker.exe OK
Extracting EXTENDED MONEY GUIDE - Make Even More Money.exe OK
Extracting BSD Hacks 100 Industrial Strength Tips Tools 2004 .pdf OK
Extracting How To Use The Checker.pdf OK
Extracting Quick Money Guide.pdf OK
All OK
pwd after: /store/ebooks/pdfs
/store/ebooks/PDF Ebook Guide Cleaning Windows XP For Dummies 2008.rar
PDF Ebook Guide Cleaning Windows XP For Dummies 2008
inside pwd: /store/ebooks/pdfs/PDF Ebook Guide Cleaning Windows XP For Dummies 2008

RAR 3.71 Copyright (c) 1993-2007 Alexander Roshal 20 Sep 2007
Shareware version Type RAR -? for help


Extracting from /store/ebooks/PDF Ebook Guide Cleaning Windows XP For Dummies 2008.rar

Extracting Crack.txt OK
Extracting Read Me First.txt OK
Extracting Checker.exe OK
Extracting EXTENDED MONEY GUIDE - Make Even More Money.exe OK
Extracting Cleaning Windows XP For Dummies 2004 .pdf OK
Extracting How To Use The Checker.pdf OK
Extracting Quick Money Guide.pdf OK
All OK
pwd after: /store/ebooks/pdfs

Migrated: from blogger 03-July-2014

Reference: