mkdir error in bash script

后端 未结 3 1868
感动是毒
感动是毒 2021-02-12 13:30

The following is a fragment of a bash script that I\'m running under cygwin on Windows:

deployDir=/cygdrive/c/Temp/deploy

timestamp=`date +%Y-%m-%d_%H:%M:%S`
de         


        
相关标签:
3条回答
  • 2021-02-12 13:52

    Change:

    mkdir -p $deploydir
    

    to

    mkdir -p "$deploydir"
    
    0 讨论(0)
  • 2021-02-12 13:55

    You can't have colons in file names on Windows, for obvious reasons.

    0 讨论(0)
  • 2021-02-12 13:56

    Change:

    mkdir -p $deploydir
    

    to

    mkdir -p "$deployDir"
    

    Like most Unix shells (maybe even all of them), Bourne (Again) Shell (sh/bash) is case-sensitive. The dir var is called deployDir (mixed-case) everywhere except for the mkdir command, where it is called deploydir (all lowercase). Since deploydir (all lowercase) is a considered distinct variable from deployDir (mixed-case) and deplydir (all lowercase) has never had a value assigned to it, the value of deploydir (all lowercase) is empty string ("").

    Without the quotes (mkdir $deploydir), the line effectively becomes mkdir (just the command without the required operand), thus the error mkdir: missing operand.

    With the quotes (mkdir "$deploydir"), the line effectively becomes mkdir "" (the command to make a directory with the illegal directory name of empty string), thus the error mkdir: cannot create directory'.

    Using the form with quotes (mkdir "$deployDir") is recommended in case the target directory name includes spaces.

    0 讨论(0)
提交回复
热议问题