First I made a file called telephone containing:Jan;032569874    Annemie;014588529    Hans;015253694    Stefaan;011802367And what I now need to do is make a script where the user inputs a name and the output should look like,The phone number of Jan is 032569874I tried a lot of things but nothing worked like its supposed to do. I know its a very easy one but I just can't get it.Ok guys those answers are clearly from a higher level. This is what I got:#!/bin/bash#Solution script2IFS=;echo Whose phone number do you want to know?read nameread name number <$1echo The phone number of $name is $number.
Search for an user name in file and output the user's phone number
scripting
Here's a roughly modified version of your script:$ more cmd.bash #!/bin/bashecho Whose phone number do you want to know?read namenumber=$(grep $name telephone | cut -d';' -f2)echo ''echo The phone number of $name is $number.It works as follows:$ ./cmd.bash Whose phone number do you want to know?HansThe phone number of Hans is 015253694.How it worksIt simply takes in the name via the read name command and stores what was typed in the variable, $name. We then grep through the file telephone and then use cut to split the resulting line from the file telephone into 2 fields, using the semicolon as the separation character. The phone number, filed 2, is stored in the variable $number.TestingYou can use the following script to test that your script works, using the data from the file telephone.$ while read -r i ;do     echo -----    echo Test \$i\    ./cmd.bash <<<$i    echo -----  done < <(cut -d';' -f1 telephone)The above commands read in the contents of the file telephone, split it on the semicolon, ;, and then takes each value from field 1 (then names) and loops through them 1 at a time. Each name is then passed to your script, cmd.bash, via STDIN, aka. <<<$i. This simulates a user typing in each of the names.$ while read -r i ;do echo -----; echo Test \$i\; \    ./cmd.bash <<<$i; echo -----; done < <(cut -d';' -f1 telephone)-----Test JanWhose phone number do you want to know?The phone number of Jan is 032569874.----------Test AnnemieWhose phone number do you want to know?The phone number of Annemie is 014588529.----------Test HansWhose phone number do you want to know?The phone number of Hans is 015253694.----------Test StefaanWhose phone number do you want to know?The phone number of Stefaan is 011802367.-----