Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 42
    shellcheck help you to improve the quality of your programs. Commented Sep 23, 2016 at 6:33
  • 4
    Besides the protective techniques described in the answers, and although it is probably obvious to most readers, I think it may be worth commenting that when files are intended to be processed using command-line tools, it is good practice to avoid fancy characters in the names in the first place, if possible. Commented Nov 10, 2016 at 13:30
  • 3
    There are now also tools to rewrite shell scripts with proper quoting. Commented Jan 20, 2017 at 19:06
  • 4
    @bli No, that makes only bugs take longer to turn up. It's hiding bugs today. And now, you don't know all filenames later used with your code. Commented Aug 7, 2018 at 6:16
  • 1
    First off, if your parameters contain spaces then they need to be quoted going in ( on the command line ). However you could grab the entire command line and parse it yourself. Two spaces don't turn to one space; any amount of space tells your script that is the next variable so if you do something like "echo $1 $2" it is your script putting one space in between. Also use "find (-exec)" to iterate over files with spaces rather than a for loop; you can deal with the spaces more easily. Commented Oct 3, 2018 at 6:05