2

ユーザー入力文字列を受け取り、それに応じて出力ファイルを作成するプログラムがあります。たとえば、「./bashexample2 J40087」は、文字列 J40087 を含むフォルダー内のすべてのファイルの出力ファイルを作成します。1 つの問題は、ユーザーが入力文字列に何も入力しない場合、格納フォルダー内のすべてのファイルに対して出力ファイルが生成されることです。ユーザーが入力文字列に何も入力できないようにする方法はありますか? または、「入力文字列を入力してください」という警告を吐き出すかもしれません。

#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
4

2 に答える 2

3

私はこのようなことをします:

tag=$1

if [ -z "$tag" ]; then
  echo "Please supply a string"
  exit 1
fi
于 2013-08-21T23:58:12.437 に答える