I have the following Bash Script:

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}"

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


You can use find ... -exec option:

find . -name iaGambro_gambro.sql -exec bash -c '
  select file do
    : Do something with "$file"
' bash {} +
|improve this answer|||||
  • 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.