For about a week I have been researching and trying to get a (nested) backup script to acquire the current major CentOS version - which it will use as part of the path to the backup server location. I've found that grep -oP '.*\K(?<=\ )[0-9](?=\.)' /etc/redhat-release returns the precise digit (albeit colored red) that I need to use to form this path directory.
Further googling for bash scripting seems to indicate that if I equate a script variable to this command within single quotes then that variable will contain the "7" or "8" that I can then concatenate to my specific path-to-proper-server-directory variable. Except I am doing something wrong with each permutation I try in my scripts. The best I come up with is a variable containing the grep command. I am sure it has everything to do with the 'escaping' (or not) of those single enclosing quotes (sometimes double quotes).
I've tried many with different variable names (currently 'release') - some attempts are:release='grep -oP '.*\K(?<=\ )[0-9](?=\.)' /etc/redhat-release'
release=\'grep -oP '.*\K(?<=\ )[0-9](?=\.)' /etc/redhat-release\'
release='grep -oP \'.*\K(?<=\ )[0-9](?=\.)\' /etc/redhat-release'
release="grep -oP '.*\K(?<=\ )[0-9](?=\.)' /etc/redhat-release"
release='/bin/bash grep -oP '.*\K(?<=\ )[0-9](?=\.)' /etc/redhat-release'
release="/bin/bash grep -oP '.*\K(?<=\ )[0-9](?=\.)' /etc/redhat-release"
and many, many more.
What am I 'just not getting'??
"release" (or whatever the variable name) never returns the text digit, but rather the command, or portions of it. I've also played with 'sed' and it's "&" - but I can't seem to get my backup script to actually acquire the result.