#! /bin/bash
# filename:FileType.sh
read -p "Please input the filename :" filename
fpath=$filename
if [ -d $fpath ]
then
echo "$fpath is a direstory."
elif [ -e $fpath ]
then
echo "$fpath is a file."
else
echo "$fpath is NOT a file or direstory."
fi
#include<stdio.h>
#include
<sys/stat.h>
#include
<unistd.h>
int
main(int
argc,char
*argv[])
{
struct
stat
st
printf("%s",argv[1])
stat(argv[1],&st)
if
(S_ISDIR(st.st_mode))
printf("is
a
dir\n")
else
printf("is
not
a
dir\n")
return
0
}
虚拟机上测过了.
是验证输入的第一个参数是不是目录.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)