シェルスクリプトパラメータ

シェルスクリプトパラメータ

次のスクリプトがあります。入力を、、、、、、-aで作成したいと思います。ただし、数値パラメータとキーワードパラメータ、およびを表すextracomパラメータには問題があります。たとえば、-s 2または-c dogまたは-d cat -bと入力するたびに、コマンドは何もしません。ディレクトリは、名前、都市、および電話番号のリストを含むtxtファイルでもあります(例:nick smith london 456523)。-l-s <number>-c <keyword>-d <keyword> -b/-r-n-b-r

#!/bin/bash

        read -rp 'choose: ' opt word extracom
            case $opt in 
            -a) echo Type name\,surname\,city\,phone number\.
                read name surname city tel
                echo $name $surname $city $tel >> list ;;
            -l) echo Shows the contents of the file\:
                cat -n catalog (|sed -i '/^$/d' list);;
            -s\ [1-4]) echo About to show the contents of a file sorted\:
                       sort -k ${opt#"-s "} catalog ;;
            -c) echo Show lines that contain the word $word
                if egrep -q "$word" catalog; then
                   cat catalog | egrep $word
                else
                   echo The string you are looking for does not exist
                fi ;;
            -d) case $extracom in
                -b) if egrep -q "$word" catalog; then
                       sed -i "s/.*$word.*//" catalog 
                   else
                       echo The string you are looking for does not exist
                   fi;;
                -r)if egrep -q "$word" catalog; then  
                      sed -i "/$word/d" catalog
                   else
                      echo The string you are looking for does not exist
                   fi;;
                esac
                ;;
            -n)egrep "^$" catalog | wc -l
                 read -rp 'Do you want to delete the file's empty lines? Yes or no?' answer
            case $answer in 
                yes) sed -i '/^$/d' catalog ;;
                no) cat catalog ;;
            esac;;
            *) echo -e 'Usage Manual:\n-a: New entry to catalog\n-l Displays the contents of the catalog without empty lines\n-s <number>: Displays
            the contents of the file sorted according to the number\n-c <keyword> shows file line that contain that specific keyword\n-d <keyword> -b/-r:
            Deletes empty file lines\n-n: Number of empty file lines and question about deleting them'
            esac

よろしくお願いします!

関連情報