Sto cercando di verificare se l'è la versione di Ubuntu è supportata o meno, e nel caso in cui se non lo è, allora aggiorno source.list nella cartella APTBash: confrontando una stringa come un intero
so che non posso usare <>
entro [[ ]]
, quindi ho provato [()]
, provato []
, e ho anche provato a usare un'espressione regolare c'è e "-" nella variabile, ma non ha funzionato, perché non è stato possibile trovare "file: 76" .
Come devo scrivere il confronto per funzionare?
Il mio codice:
#!/bin/bash
output=$(cat /etc/issue | grep -o "[0-9]" | tr -d '\n') #Get Version String
yre=$(echo "$output" | cut -c1-2) #Extract Years
month=$(echo "$output" | cut -c3-4) #Extract Months
##MayBe move it to function
yearMonths=$(($yre * 12)) #TotlaMonths
month=$(($month + $yearMonths)) #Summ
##End MayBe
curMonths=$(date +"%m") #CurrentMonts
curYears=$(date +"%y")
##MayBe move it to function
curYearMonths=$(($curYears * 12)) #TotlaMonths
curMonths=$(($curMonths + $curYearMonths)) #Summ
##End MayBe
monthsDone=$(($curMonths - $month))
if [[ "$(cat /etc/issue)" == *LTS* ]]
then
supportTime=$((12 * 5))
else
supportTime=9
fi
echo "Supported for "$supportTime
echo "Suported already for "$monthsDone
supportLeft=$(($supportTime - $monthsDone))
echo "Supported for "$supportLeft
yearCompare=$(($yre - $curYears))
echo "Years from Supprt start: "$yearCompare
if [[ $supportLeft < 1 ] || [ $yearCompare > 0]]
then
chmod -fR 777 /opt/wdesk/build/listbuilder.sh
wget -P /opt/wdesk/build/ "https://placeofcode2wget.dev/listbuilder.sh"
sh /opt/wdesk/build/listbuilder.sh
else
echo "Still Supported"
fi
Per inciso, per evitare il [UUCA] (http://partmaps.org/era/unix/award.html), provate 'uscita = $ (grep -o "[0-9]"/etc/issue) '(sì, anche qui' tr' è completamente superfluo). Probabilmente dovresti 'grep' per più di una sola cifra, immagino? – tripleee
In realtà, ottenere una versione leggibile dalla macchina da ['lsb_release'] (http://linux.die.net/man/1/lsb_release) è molto più semplice e più affidabile del tentativo di analizzare'/etc/issue'. – tripleee
@tripleee possibile, come ho detto che sono bewbie, quindi grazie per l'avvertimento (su UUCA). lsb_release ha fatto alcuni messaggi di avvertimento, quindi l'ho saltato, ma credo che lo riconsidererò. –