創建一個shell腳本調用file.sh:
#!/bin/bash
# file.sh: a sample shell script to demonstrate the concept of Bash shell functions
# define usage function
usage(){
echo "Usage: $0 filename"
exit 1
}
# define is_file_exits function
# $f -> store argument passed to the script
is_file_exits(){
local f="$1"
[[ -f "$f" ]] && return 0 || return 1
}
# invoke usage
# call usage() function if filename not supplied
[[ $# -eq 0 ]] && usage
# Invoke is_file_exits
if (is_file_exits "$1")
then
echo "File found"
else
echo "File not found"
fi
運行它,如下所示:
chmod +x file.sh
./file.sh
./file.sh /etc/resolv.conf
什麼是你的問題? –
sry,我編輯它 –