我有一个程序,它将接受用户输入字符串并相应地创建输出文件,例如,“./bashexample2 J40087”这将为文件夹中包含字符串 J40087 的所有文件创建输出文件。一个问题是,如果用户没有在输入字符串中输入任何内容,它将为包含文件夹中的每个文件生成输出文件。有没有办法阻止用户在输入字符串中输入任何内容?或者可能会吐出某种警告说“请输入输入字符串”。
#Please follow the following example as input: xl-irv-05{kmoslehp}312: ./bashexample2 J40087
#!/bin/bash
directory=$(cd `dirname .` && pwd) ##declaring current path
tag=$1 ##declaring argument which is the user input string
echo find: $tag on $directory ##output input string in current directory.
find $directory . -maxdepth 0 -type f -exec grep -sl "$tag" {} \; ##this finds the string the user requested
for files in "$directory"/*"$tag"* ##for all the files with input string name...
do
if [[ $files == *.std ]]; then ##if files have .std extensions convert them to .sum files...
/projects/OPSLIB/BCMTOOLS/sumfmt_linux < "$files" > "${files}.sum"
fi
if [[ $files == *.txt ]]; then ## if files have .txt extensions grep all fails and convert them..
egrep "device|Device|\(F\)" "$files" > "${files}.fail"
fi
echo $files ##print all files that we found
done