Rechercher un identifiant et renvoyer le nom sur cette ligne

J’utilise Linux et je suis nouveau dans le codage et j’ai besoin d’aide pour un projet.

#!/bin/bash # findName.sh - written by Corey Brown # # for use in some project File="/acct/common/CSCE215-Fall17" if [[ $1 = "" ]] ; then echo "usage: `basename $0` [only_one_argument]" exit 2 fi # read the file line by line while read LINE do # file format: First, Middle, Last, UserID # set the index values based on the line format given above firstNameIndex=0 middleNameIndex=1 lastNameIndex=2 userIDIndex=3 # read the line into an array IFS=', ' read -r -a lineArray <<< "$LINE" # if the passed parameter equals the value of the line at userIDIndex if [[ $1 -eq ${lineArray[$userIDIndex]} ]] ; then echo ${lineArray[$firstNameIndex]} ${lineArray[$middleNameIndex]} ${lineArray[$lastNameIndex]} exit 1 fi done < "$File" 

Le but est de rechercher un identifiant d’utilisateur et de trouver le nom qui lui est associé. Le format du fichier que je recherche est FirstName,MiddleName,LastName,UserID . Il y a 78 lignes avec un identifiant et un nom d’utilisateur différents. C’est le fichier:

 Adarius,Macarthy,Adams,adamsam9 Ahmed,Abdulkarim,Hulwe,ahmedh Ainsley,Grace,McWaters,mcwatera Alexander,Steven,Hammett,hammeta Allison,Rose,Rogers,arr2 Andrew,Robert,Tant,atant Ashton,Nathaniel,Bass,anbass Austin,Michael,Aguilera,ama4 Austin,Thomas,Blackwell,atb Ayla,Beth,Nickerson,aylan Bennett,Steven,Marra,bmarra Brennan,Sanders,Cain,bscain Brian,William,Greene,bwgreene Byron,Javier,Carranza,carranza Cardi,Stone,Ireland,cireland Chad,Allen,Kraus,ckraus Chandni,Bhavesh,Amin,camin Chase,Michael,Henry,chasemh Christian,Alexander,Brock,cab11 Christofer,Thomas,Cooper,cooperct Christopher,Gregory,Masselli,masselli Cody,James,Rose,cjrose Colby,Franklin,McHugh,cmchugh Cole,Peiffer,Kirby,cpkirby Connor,Niles,Latterell,cnl Conrad,Joseph,Hetzer,chetzer Corey,Daniel,Brown,browncd4 Curtis,Allen,Ward,curtisaw Dajshan,Montrel,Murphy,dajshan Damion,Ray'shard,Graham,drgraham Denzel,Malik,Wilson,dmwilson Derek,,Hebert,dhebert DeVonte,,Lyles,dlyles D'misorting,Lamont,Williams,dmisorting Dorothy,Candra,Joyner,dcjoyner Drew,Graham,Bussey,dgbussey Edward,A,Perreyclear,perreyce Emmett,Poindexter,Hatcher,ehatcher Eric,Wayne,Davies,ewdavies Frances,Leah,Dickson-Vandervelde,fld1 Hayley,Cy,Lichtenfels,hayleyl Hendrick,Samuel,McCullar,hsm1 Hunter,Jarrett,Damron,hdamron Ibrahim,J,Salman,ijsalman Jahred,Elisha,Danker,jdanker James,Wade,Curlee,jcurlee Jared,Edward,Elliott,jarede John,M,Lee,jml4 Jonathan,,Isaac,ji7 Joseph,Chambers,Martin,jcm5 Kaitlyn,Marie,Ash,kmash Kristeen,Elizabeth,Ginn,keginn Kunj,Girish,Naik,kgnaik Logan,Robert,Orr,lrorr Luke,Ellison,Whittle,whittlel Luke,Joseph,Imholz,limholz Mackenzie,Carter,West,mcw3 Matthew,Robert,Lassiter,lassitm Matthew,Thomas,O'Neill,mtoneill Nathaniel,James,Mills,njmills Nicole,,Dorney,ndorney Pranav,Raghu,Minasandram,pranavm Ralph,Tristin,DeFilio,rdefilio Robert,Brogdon,Gamble,rbgamble Rohan,,Bhandari,rohanb Silas,,Steiger,ssteiger Steven,Edward,Maxwell,sem15 Steven,George,Edwards,stevenge Suzanne,Terese,Prentice,suzannep Taylor,Aric,Gordon,tag2 Thomas,Matthew,Sullivan,tms3 Vincent,Cordell,Arceo,varceo Wade,Christopher,Lewis,wclewis Wade,Prescott,Morgan,wpmorgan William,Alexander,Simmons,wsimmons William,Dale,Hudson,whudson Zachary,Dylan,Smith,zds Zachary,Paul,Stump,zstump 

Donc, c’est le code, maintenant quand je lance le script et que je passe un argument, il me donnera toujours la première ligne de la liste:

 $ ./findName.sh zds $ Adarius Macarthy Adams $ 

et quand je ne passe pas un argument, il imprime la liste entière. Je prends les indices mais je ne peux pas comprendre où je vais mal.