Shell 脚本:判断参数是文件还是文件夹
#!/bin/bash
if [ -d '$1' ]; then echo '$1 is a directory.' elif [ -f '$1' ]; then echo '$1 is a file.' else echo '$1 is not a valid file or directory.' fi
这个脚本接受一个参数,可以是文件或目录的路径
如果参数是目录,输出“xxx is a directory.”
如果参数是文件,输出“xxx is a file.”
如果参数不是有效的文件或目录,输出“xxx is not a valid file or directory.”
原文地址: https://www.cveoy.top/t/topic/ojem 著作权归作者所有。请勿转载和采集!