如题 shell script 中 if [ $1 ] 和 if [ -a $1] 区别
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/10/01 06:27:40
如题 shell script 中 if [ $1 ] 和 if [ -a $1] 区别
if [ $1 ] 判断参数是否存在
-bash-4.1$ sh one.sh
please para:
-bash-4.1$ sh one.sh testOne
para: testOne
-bash-4.1$ cat one.sh
#!/bin/bash
if [ $1 ]
then
echo "para: $1" #有参数testOne 输出此行
else
echo "please para:" #没有参数testOne 输出此行
fi
-bash-4.1$
if [ -a $1] 判断文件或目录是否存在,即$1变量上面对应的是testOne
-bash-4.1$ ls
one.sh te.sh testOne two.sh //此目录下,文件列表
-bash-4.1$ sh two.sh adf // 没有这个文件adf
no exist file: adf
-bash-4.1$ sh two.sh testOne // 有这个文件夹testOne
exist file : testOne
-bash-4.1$ cat two.sh //脚本内容
#!/bin/bash
if [ -a $1 ]
then
echo "exist file : $1"
else
echo "no exist file: $1"
fi
-bash-4.1$
-a现在一般情况下都会用-e来替换.
-bash-4.1$ sh one.sh
please para:
-bash-4.1$ sh one.sh testOne
para: testOne
-bash-4.1$ cat one.sh
#!/bin/bash
if [ $1 ]
then
echo "para: $1" #有参数testOne 输出此行
else
echo "please para:" #没有参数testOne 输出此行
fi
-bash-4.1$
if [ -a $1] 判断文件或目录是否存在,即$1变量上面对应的是testOne
-bash-4.1$ ls
one.sh te.sh testOne two.sh //此目录下,文件列表
-bash-4.1$ sh two.sh adf // 没有这个文件adf
no exist file: adf
-bash-4.1$ sh two.sh testOne // 有这个文件夹testOne
exist file : testOne
-bash-4.1$ cat two.sh //脚本内容
#!/bin/bash
if [ -a $1 ]
then
echo "exist file : $1"
else
echo "no exist file: $1"
fi
-bash-4.1$
-a现在一般情况下都会用-e来替换.
shell脚本if [ $1
bash shell中if [-f $2]和echo -e是什么意思
shell相关 请问if [ "${0:0:1}" != "/" ] ; then中${0:0:1}的具体解释
if[[$#-eq 1]] then a=$1 fi shell程序里面这个是什么意思呀
shell 中的下面这句话是什么意思 if [ "${1:-NULL}" = "A" ]; then fi
if (check) 和 if (check=1) 有区别么
C语言中,If(a==b)和if(a=b)什么区别?
shell脚本中 if 判断时候-s是什么意思
linux shell的if语句
if else 和 if if 的区别
php中if ($goods)和if isset($goods)的区别
在shell脚本中有个语句是if [ -d $1"/"$file ],其中 $1"/"$file是什么意思