Shell variable issue when trying to mkdir

前端 未结 3 1180
遇见更好的自我
遇见更好的自我 2021-01-02 00:32

Any ideas what is wrong with this code?

CLIENT_BUILD_DIR=\"~/Desktop/TempDir/\"

if [ ! -d $CLIENT_BUILD_DIR ]
then
   {
      mkdir $CLIENT_BUILD_DIR
   }
f         


        
相关标签:
3条回答
  • 2021-01-02 01:06

    The quotes prevent the expansion of ~.

    Use:

    CLIENT_BUILD_DIR=~/Desktop/TempDir/
    
    if [ ! -d "$CLIENT_BUILD_DIR" ]
    then mkdir "$CLIENT_BUILD_DIR"
    fi
    
    0 讨论(0)
  • 2021-01-02 01:07

    The ~ character is not reinterpret when used in a variable.

    You can use CLIENT_BUILD_DIR="$HOME/Desktop/TempDir/" instead.

    0 讨论(0)
  • 2021-01-02 01:13

    mkdir ${CLIENT_BUILD_DIR} will do. No directory will be created if it already exists.

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