I am trying to write a shell script to search a cell value in a csv file and replace a corresponding cell in the same row.

Below is my csv file (`report.csv`)

> 
> **#,Device,Status**  
> 
> 1,Device1,Used  
> 
> 2,Device2,Free  
> 
> 3,Device3,Free
> 
> 
> 

This is want I wanted to do:

User will enter device name as input while executing the script.

e.g., Enter the device name:  

user enters "Device2"

Next step: script should search for **Device2** in `report.csv`. If it finds **Device2**, check the value in the **status** column corresponding to it and, if the value is **Free**, replace it as **Used**, else exit the script saying **Device2 already in use**.

I have tried with following code

```
#!/bin/bash
dvc=""
FILE_HOME="/tmp/test/"

update_value () {  
  awk -F, -v d="$dvc" '$2==d{if($3=="Free")$3="Used"; else print d "In use"; input_value;}1' \
      OFS=, "$FILE_HOME"/report.csv > "$FILE_HOME"/report1.csv  
  mv "$FILE_HOME"/report1.csv "$FILE_HOME"/report.csv
}

input_value () {
  echo -e "Enter the device name:\n"
  read dvc
  update_value
}

input_value

```

This code is fine when the **if** statement is **true**.  

But when the **if** statement is **false**, it is not calling function `input_value` from the else section.  It just prints **Device# In use** along with other entries in csv file to new file.

I get below output files

* when input is **Device2**:

> 
> **#,Device,Status**  
> 
> 1,Device1,Used  
> 
> 2,Device2,Used  
> 
> 3,Device3,Free
> 
> 
>
* when input is **Device1**:

> 
> **#,Device,Status**  
> 
> Device1 In use  
> 
> 1,Device1,Used  
> 
> 2,Device2,Free  
> 
> 3,Device3,Free
> 
> 
>

Is this the right approach I am doing?  

I would be happy to see if there a different/better approach to achieve the requirement.