Consider the below example:
Parameter1 = 5
Parameter2 = 10
Parameter3 = 15
Parameter4 = 20
I want to fetch the value depending on the parameter name by providing a user input as shown below:
echo ""
echo " Enter the parameter name"
read value
Parameter = "$value"
Check if the parameter is existing within the concern file
if grep -qs "$Parameter" "Filename"
then
echo " Parameter exist within the concern file"
val = #Here I want to fetch the value of the parameter that the user had input and I do not know how to do it?
Kindly let me know how I can fetch the value of the parameter which the user had given as input.
If I understand you correctly, you could use something like this:
read param_name # e.g. Parameter2
value=$(awk -v param="$param_name" '$1 == param { print $3 }' filename)
This reads the name of the parameter then prints the third field on the line when the first field matches the name. The result is assigned to the shell variable $value
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.