如何在脚本中使用通配符

时间:2017-08-31 15:21:45

标签: shell

我正在使用!/bin/ksh

我的团队有一个脚本,可以从屏幕上获取用户输入。用户输入grep A0 /dir/dir1/dir2/*filename*。如果代码输入文件名或目录,则代码有效。如果用户输入*filename*(或filename*),它就不起作用。用户未找到匹配项'。

func_grep()
{
getstr "Search command: " cmdstr
search_cmd=`echo $cmdstr | awk '{ print $1 }'`

expandstr "$cmdstr" /* expandstr assigns v1_file. This part is working
cmd_opt=`echo $cmdstr | awk 'NF > 3 { print $2 }'`
search_key=`echo $cmdstr | awk '{ print $(NF-1)}'`
chk_str $v1_file
if [ $? -eq "0" ]
then
      if [ -d $v1_file ]  # if input is directory then append "*" to
      then                # search for entire directory
             v1_file="$v1_file/*"
      fi
      $search_cmd $cmd_opt $search_key $v1_file > /ercs/ercs000/reports/gr
ep_$LOGNAME

case $? in
             0) echo "\nThe grep output file: /ercs/ercs000/reports/grep_$LOG
             NAME has been created." ;;
             1) echo "\n\tNo matches were found." ;;
             *) echo "\n\tSyntax  errors  or  inaccessible  files."
                echo "\t$search_cmd $search_key $v1_file"
                return 1 ;
 esac
}

0 个答案:

没有答案
相关问题