I am new to shell script programming. I want to write a simple shell script to check the ubuntu version installed in the system; if the version is greater than or equal to version 12 then copy some files, and if it's less then copy some other files.
The lsb_release -rs command lets us determine the Ubuntu version, we could use it like this:
if [[ $(lsb_release -rs) == "18.04" ]]; then # replace 8.04 by the number of release you want
echo "Compatible version"
#Copy your files here
else
echo "Non-compatible version"
fi
`` (enclosing backticks) is non-POSIX and deprecated.
cat /etc/issue.net | awk '{x=2 ; if (substr($x,0,3) == '12') {system("cp <src> <dest>") } else {system("cp <src> <dest>") }}'
cat /etc/issue.net will show 3 fields out of which 2nd field is version no.
by substr we check the first two digit if it is version 12 then by system command inside awk we can copy certain files from a particular src to dest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With