I have a file that I need to look up a value by key using a shell script. The file looks like:
HereIsAKey This is the value
How can I do so
If you only need one variable at a time, you can do something like this:
#!/bin/bash
cat file | while read key value; do
echo $key
echo $value
done
The problem with this solution: The variables are only valid inside the loop. So don't try to do $key=$value and use it after the loop.
Update: Another way is I/O redirection:
exec 3