Is there a version of the pick script that will work properly with spaces in the filenames?

This is a tricky question—pick is trivial to enhance to work with spaces in filenames, but the output is just the filenames—with no indication of where a fillename begins or ends.

My goal is to be able to say something like

for i in `pick .??*` ; do ... ; done

But that is, as far as I can tell, hopeless; even using the $() syntax instead of the backticks, how do you get the filenames intact from the selection to the processing?

The only tool I can think of that comes close is xargs -0, which lets me have arbitrary names -- but I don't know how to interface to that except from find -0.

EDIT: Pick is a script that takes a bunch of files, and asks you which ones you want or don't want.

See http://examples.oreilly.de/english_examples/upt3/split/pick for a sample. It's not complicated, but if you don't know how to redirect inside a shell script, or have never seen that construct before, it will be a surprise.

And yes, it outputs one filename per line.

  • 4
    What is the pick script and what does it do? I have never heard of it – Graeme Oct 4 '14 at 17:37
  • Information added to the problem description. – Keybounce Oct 4 '14 at 22:41

If pick outputs of filename per line, you can set IFS to contain a newline only. Eg (in bash):

for i in $(pick .??*) ; do ... ; done

This will allow your filenames to contain spaces and tabs, of course if they contain newlines there will still be a problem. You may also want to consider disabling globbing if there are any filenames with glob characters (eg * or ?). Use set -f to disable and set +f to reenable.

find -name "* *" -type f -exec rename 's/ /_/g' {} +

Replace the spaces in your filenames with "_".

Then use pick.

Rationale: Spaces in file names are typically considered a non-standard file naming convention. Successful I.T. is about doing things the same way every time, reminiscent of Sun Tzu's art of war: pick your battles carefully.

  • 1
    Sadly, I cannot control the names that will be used by other programs. – Keybounce Oct 4 '14 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.