简体   繁体   中英

Check if argument is a file or directory

I am trying to check if an argument is a directory or a file. I want to put a / after each directory name and a * after every executable file. I know ls uses -F to get this information but I can't figure this out in my script.

Here is my code:

    echo -n "Please enter Directory name you wish to search: "
read dir

for filename in "/home/me/Desktop/$dir"/*

do

    if (-F $filename)
    then 
    echo $filename

    fi
done

[ -f "$filename" ]对于文件为true, [ -d "$dirname" ]对于目录为true。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM