How can Linux determine if the incoming parameter is a file?

In Linux, the -f option can be used to determine if the incoming parameter is a file.

Here is an example Shell script that can check if the input parameters are files.

#!/bin/bash

if [[ -f "$1" ]]; then
    echo "$1 是一个文件"
else
    echo "$1 不是一个文件"
fi

In the above script, the -f option is used to determine if $1 is a file. If it is a file, it will output $1 is a file; if it is not a file, it will output $1 is not a file.

You can use the following command to run the script above and pass in the parameter that needs to be evaluated:

bash script.sh <参数>

One of the parameters that needs to be evaluated is .

广告
Closing in 10 seconds
bannerAds