Remove unnecessary variable usage

We don't need to use device_list variable while devices variable can be directly used
This commit is contained in:
Jeevitha Kannan K S 2024-11-20 11:44:38 +05:30
parent c73fd51058
commit b1b7ce0527
No known key found for this signature in database
GPG Key ID: 5904C34A2F7CE333

View File

@ -82,9 +82,8 @@ prompt_for_mac() {
fi fi
# Display devices with numbers # Display devices with numbers
device_list="$devices"
i=1 i=1
echo "$device_list" | while IFS= read -r device; do echo "$devices" | while IFS= read -r device; do
printf "%d. %s\n" "$i" "$device" printf "%d. %s\n" "$i" "$device"
i=$((i + 1)) i=$((i + 1))
done done
@ -92,11 +91,11 @@ prompt_for_mac() {
printf "%b" "$prompt_msg" printf "%b" "$prompt_msg"
read -r choice read -r choice
count=$(printf "%b" "$device_list" | wc -l) count=$(printf "%b" "$devices" | wc -l)
count=$((count + 1)) count=$((count + 1))
if echo "$choice" | grep -qE '^[0-9]+$' && [ -n "$choice" ] && [ "$choice" -le "$count" ] && [ "$choice" -gt 0 ]; then if echo "$choice" | grep -qE '^[0-9]+$' && [ -n "$choice" ] && [ "$choice" -le "$count" ] && [ "$choice" -gt 0 ]; then
device=$(echo "$device_list" | sed -n "${choice}p") device=$(echo "$devices" | sed -n "${choice}p")
mac=$(echo "$device" | awk '{print $2}') mac=$(echo "$device" | awk '{print $2}')
if bluetoothctl info "$mac" >/dev/null 2>&1; then if bluetoothctl info "$mac" >/dev/null 2>&1; then
if bluetoothctl "$command" "$mac"; then if bluetoothctl "$command" "$mac"; then
@ -105,12 +104,10 @@ prompt_for_mac() {
else else
printf "%b\n" "${RED}$failure_msg${RC}" printf "%b\n" "${RED}$failure_msg${RC}"
read -r _ read -r _
fi fi
else else
printf "%b\n" "${RED}Invalid MAC address. Please try again.${RC}" printf "%b\n" "${RED}Invalid MAC address. Please try again.${RC}"
read -r _ read -r _
fi fi
elif [ "$choice" -eq 0 ]; then elif [ "$choice" -eq 0 ]; then
return return