A
A
antimodern2019-02-21 01:22:39
bash
antimodern, 2019-02-21 01:22:39

Why does the script not work with files with spaces?

There is a script, but it breaks if the files contain spaces in the name. How to fix?

for font in $(ls); do
  if  || ;then
    echo "$font"
    $HOME/Downloads/sfnt2woff-zopfli-master/sfnt2woff-zopfli "$font"
    $HOME/Downloads/woff2/woff2_compress "$font"
  fi
done

The script is run in a directory, selects files with .otf or .ttf resolution and converts them. The problem is that if the script sees only the last word + file permission in a file with spaces, the path is broken accordingly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2019-02-21
@antimodern

Take it in quotation marks.

IFS=$'\n'
for font in $(ls -1); do
  if  || ; then
    echo "$font"
    $HOME/Downloads/sfnt2woff-zopfli-master/sfnt2woff-zopfli "$font"
    $HOME/Downloads/woff2/woff2_compress "$font"
  fi
done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question