如果[-d" $ / root / folder" ]。不管用

时间:2018-03-27 12:32:50

标签: shell

如果目录中还没有目录,我需要在Linux的根目录中创建一个目录。所以我使用if [-d" $ / root / folder" ]。但即使目录存在,它也会转向其他部分。请帮忙。以下是代码 -

#! /bin/sh
if [ -d "$/root/folder" ];then
   echo "folder file already exist"
else
   echo "Settings in progress" \
&& mkdir folder   \
&& chmod 7777 folder \
&& cd folder \
&& mkdir FolderConnector \
&& chmod 7777 FolderConnector \
&& cd FolderConnector \
&& mkdir ClientInput \
&& mkdir ClientOutput \
&& chmod 7777 ClientInput \
&& chmod 7777 ClientOutput \
&& cat /home/data/RTV/file2 >>/etc/exports \
&& exportfs -r \
&& exportfs \
&& echo "Settings completed successfully."  
fi

1 个答案:

答案 0 :(得分:0)

我会做什么:

#! /bin/sh
set -e

if [ -d "/root/folder" ]; then
    echo "folder file already exist"
else
    echo "Settings in progress"
    mkdir folder   
    chmod 7777 folde
    cd folder
    mkdir FolderConnector 
    chmod 7777 FolderConnector 
    cd FolderConnector 
    mkdir ClientInput 
    mkdir ClientOutput 
    chmod 7777 ClientInput 
    chmod 7777 ClientOutput 
    cat /home/data/RTV/file2 >>/etc/exports 
    exportfs -r 
    exportfs 
    echo "Settings completed successfully."
fi
  • set -e停止第一个错误的脚本
  • 你的考试中有$个字符