可以使用以下的shell脚本函数来判断某个文件是否存在:

check_file_exists() {
    if [ -e "$1" ]; then
        echo "File $1 exists."
    else
        echo "File $1 does not exist."
    fi
}

这个函数接受一个参数作为文件路径,然后使用-e选项来判断文件是否存在。如果文件存在,则输出提示信息"File [文件路径] exists.",否则输出"File [文件路径] does not exist."。

你可以将这个函数添加到你的shell脚本中,并在需要的地方调用它来判断文件是否存在。例如:

check_file_exists "/path/to/file.txt"

请将/path/to/file.txt替换为你想要检查的文件路径。

linux shell 判断某个文件是否在不在则给出提示封装成函数

原文地址: http://www.cveoy.top/t/topic/it8F 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录