[jerry@localhost bin]$ cat if-else.sh
#!/bin/bash
directory="./hard_one"
if [ -d $directory ]; then
echo "Directory exists"
else
echo "Directory not exits"
fi
[jerry@localhost bin]$ ./if-else.sh
Directory exists
=====================
[jerry@localhost bin]$ cat if-else2.sh
#!/bin/bash
if [ -d $1 ]; then
echo "$1 Directory exists"
else
echo "$1 Directory not exits"
fi
[jerry@localhost bin]$ ./if-else2.sh hard_one
hard_one Directory exists
#!/bin/bash
directory="./hard_one"
if [ -d $directory ]; then
echo "Directory exists"
else
echo "Directory not exits"
fi
[jerry@localhost bin]$ ./if-else.sh
Directory exists
=====================
[jerry@localhost bin]$ cat if-else2.sh
#!/bin/bash
if [ -d $1 ]; then
echo "$1 Directory exists"
else
echo "$1 Directory not exits"
fi
[jerry@localhost bin]$ ./if-else2.sh hard_one
hard_one Directory exists
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23895263/viewspace-697724/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/23895263/viewspace-697724/