2

This question already has an answer here:

I have a script like this:

mkdir "$test"

If $test is empty, as with nothing then touch will complain with this:

touch: cannot touch '': No such file or directory

If I remove the " then I get the behavior I'm expecting mkdir: missing operand.

The issue is If I ever have filenames with spaces in $test it will break my script. I need to do it in a way that $test can be empty or have spaces in it, and do not mess with my command either way.

In my real script the command line I'm using should just ignore $test if it's empty like it happens when not quoted, but need to work with spaces too. The issue is this '' stuff that appears in my command line.

marked as duplicate by muru, Community Nov 17 '18 at 9:11

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
    @muru Thanks! I did not found it by googling, but I help this question will help people get to that question with different search keywords – Freedo Nov 17 '18 at 9:12

Browse other questions tagged or ask your own question.