I wanted to ask the more experienced bash scripters for an advice with the script I attempting to write.
The script should get the version from the "dependencies" (Depends, Suggest, etc.) fields from the /var/lib/dpkg/status file.
I tryed to do some code, but with no positive result. Bellow I type my experimental code and count on any ideas how to improve it to make the code work as expected.
NOTE: The echo -e "\n(...)\n"
statement is for verification propouses only
#!/bin/bash
## This causes that instead displaying only line with the "Depends" it display's
## the whole file with destroyeed formating (like inline)
while read a; do
data="$(echo $a | grep 'Depends: ')"
echo -e "\n[Test] Content: ${data}\n"
## This part isn't working. I tryed with escaping with '\' but it didn't helped
## to make it working :-(
# fields_split="$(echo $data | awk -F ', ')"
# echo -e "\n[Test] Fields split: ${fields_split}\n"
# start_split="$(echo ${fields_split} | awk -F '(')"
# echo -e "\n[Test] Start split: ${start_split}\n"
# end_split="$(echo ${fields_split} | awk -F ')')"
# echo -e "\n[Test] End split: ${end_split}\n"
# start_len=$(expr ${#start_split}+1)
# echo -e "\n[Test] Start length: ${start_len}\n"
# end_len=$(expr ${end_split}+1)
# echo -e "\n[Test] End length: ${end_len}\n"
# out="${fields_split:${start_len}:${end_len}}"
# echo -e "\n[Test] Cut out the version: ${out}\n"
done <<< $(cat /var/lib/dpkg/status)
Any ideas ?