0

This question already has an answer here:

I have the following Bash Script:

#!/bin/bash
cd ~/Library/Developer/CoreSimulator/Devices/;

files=$(find . -name iaGambro_gambro.sql)

select file in $files; do
    if [ -n "$files" ]; then
        sudo sqlite3 -header -column "${file}"
    fi
    break
done

It should return the following 2 results:

1) ./2EFF5EBF2B2D/Library/Private Documents/iaGambro_gambro.sql
2) ./A1AF3463BFD2/Library/Private Documents/iaGambro_gambro.sql

But it is is returning the following 4 because of the white space in Private Documents:

1) ./2EFF5EBF2B2D/Library/Private 
2) Documents/iaGambro_gambro.sql
3) ./A1AF3463BFD2/Library/Private 
4) Documents/iaGambro_gambro.sql

How do I get the select to recognize the paths with the spaces?

NOTE: I'm looking for how to execute on the given path, not just print it out

marked as duplicate by jordanm, cuonglm, Stephen Kitt, jasonwryan, Anthon May 4 '15 at 19:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

You can use find ... -exec option:

find . -name iaGambro_gambro.sql -exec bash -c '
  select file do
    : Do something with "$file"
    break
  done
' bash {} +
  • am I right to assume : Do something with "$file" is sudo code? – Seth McClaine May 4 '15 at 15:40
  • @SethMcClaine: Yes, whatever you want to do with "$file" – cuonglm May 4 '15 at 15:41
  • ok, I think thats what I'm looking for, confirming now – Seth McClaine May 4 '15 at 15:41

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