Bash scripting: variable name made partially out of other variable name

i have just done some more scripting on my pacui package manager.

in the process i struggled to do the following:

var1 is given as shown below. i want var2 to be the last part of var1. i solved the problem with the following code:

var1="  5 6 "
var2=$( echo $var1 | awk '{print $2}' )

i do not like this code at all, but i have not found an easier solution. do you have any suggestions?

just if somebody wants to know the bash code in pacui i am talking about:

i dont view the content of file /tmp/pacui-downgrade-counted (hard to answer) but :
just read temp1 temp2 ?

while read -r temp1 temp2 
    #temp1=$( echo $line | awk '{print $1}' )   # this variable
    #temp2=$( echo $line | awk '{print $2}' )

other convert to array :

line="  5 6 "
echo "var1:${line[0]}"
echo "var2:${line[1]}"

note L257,L267...L293 grep + awk

#grep upgraded /tmp/pacui-cache-packages | awk '{print $2}' 
awk '/upgraded/ {print $2}' /tmp/pacui-cache-packages

for inc a number dont use (($number)) just ((number))

1 Like

Forum kindly sponsored by