如何检查目录是否给出论据

时间:2017-04-04 01:51:45

标签: unix scripting

如果参数为0,那么脚本应检查名为“App0”的目录是否在windows路径变量中。如果不存在,则在路径中添加\ App0。我正在努力理解(如果论证是0)。

我的工作到目前为止。

if [ -d "${Appo}" ]; then
    echo "Appo Doesn't Exist."    
    mkdir Appo
    echo "File Created"
fi

谢谢

1 个答案:

答案 0 :(得分:-1)

#!/bin/sh

if [[ $# == 0 ]]
then
    echo "zero args"
fi

for arg in "$@"   # You might get more than one argument.
do
    dir="App${arg}"   # Make the name by combining the strings.
    if [[ -d $dir ]] 
    then
        echo "App$arg exists"
    else
        mkdir "$dir"  # Be careful the name supplied may contain spaces.
        echo "Created directory: $dir"
    fi
done