echo -e Please input a filenameI will check the filenames typeread -p Input a filename filenametest -z $filename && echo you must input a filename && exit 0iftest ! -e logical ;thentouch logicexit 0el
The script seems to have some syntax errors. Here's a corrected version:
#!/bin/bash
echo "Please input a filename. I will check the filename's type." read -p "Input a filename: " filename
if [ -z "$filename" ]; then echo "You must input a filename." exit 1 fi
if [ ! -e "$filename" ]; then echo "File does not exist. Creating empty file." touch "$filename" elif [ -d "$filename" ]; then echo "Directory." elif [ -f "$filename" ]; then echo "Regular file." else echo "Other type of file." fi
exit 0
This script asks the user for a filename, checks if it exists and what type of file it is (directory, regular file, or other), and creates an empty file if it doesn't exist. It also includes some error handling in case the user doesn't input a filename
原文地址: https://www.cveoy.top/t/topic/eYjU 著作权归作者所有。请勿转载和采集!