当前位置: 技术问答>linux和unix
shell进行文件存在性判断,总是找不到
来源: 互联网 发布时间:2016-10-30
本文导语: #!/bin/sh PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH #filename1 while [ 1=1 ] do read -p "please input the name of a file:" filename1 if ! [-e ${PWD}/$filename1] ;then echo ${PWD}/"$filename1 not found.Please try...
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#filename1
while [ 1=1 ]
do
read -p "please input the name of a file:" filename1
if ! [-e ${PWD}/$filename1] ;then echo ${PWD}/"$filename1 not found.Please try again"
elif ! [-f ${PWD}/$filename1] ;then echo ${PWD}/"$filename1 not a file.Please try again"
else break
fi
done
#filename2
while [ 1=1 ]
do
read -p "please input the name of a file:" filename2
if ! [-e $PWD/$filename2] ;then echo " $filename2 not found.Please try again"
elif ! [-f $PWD/$filename2] ;then echo " $filename2 not a file.Please try again"
else break
fi
done
#begin Merge
fileName= "${filename1%.*}${filename2%.*}"
fileExtension=${filename1##*.}
touch filename.fileExtension
cat filename1 filename2 > filename.fileExtension
exit 0
##
######进行对两个文件进行合并的操作,但是总找不到【实际上,test目录下有qq.sh】,如
please input the name of a file:qq.sh
FileMerge.sh:12:[-e:not found
/home/yangbo/test/qq.sh not found.........
|
[ ] 前后要有空格
|
[ -n "`ps -ef|grep $PWD/a|grep -v grep`" ]
[ -n "`ps -ef|grep $PWD/b|grep -v grep`" ]
加引号,
或者改用
[[ -n `ps -ef|grep $PWD/a|grep -v grep` ]]
[[ -n `ps -ef|grep $PWD/b|grep -v grep` ]]
双方括号
|
正解,有可能路径中有"/"