You are not logged in.
Hi all,
i'm newbie in a Forum and have a question for more experts.
I created a script for automate pacman.
The script contains the main commands but not those for installing and removing because i don't know the way to bring it up "sudo pacman -S" or "sudo pacman -Rs" and add the name of package.
Thank you for support.
Last edited by pikomarco (2023-01-20 08:44:16)
Offline
because i don't know the way to bring it up "sudo pacman -S" or "sudo pacman -Rs" and add the name of package
Bring what up?
I guess you're looking for an interactive GUI way to issue a password to sudo?
You can use https://man.archlinux.org/man/core/sudo/sudo.8.en#S or alternatively pkexec, but it's really not clear to me what you want to achieve.
Offline
I rather think OP does not know how to format / concatenate string literals in $SCRIPT_LANGUAGE they are using.
Which would be reasons enough for me to not engage any further in here.
Last edited by schard (2023-01-17 13:07:10)
Inofficial first vice president of the Rust Evangelism Strike Force
Offline
I rather think OP does not know how to format / concatenate string literals in $SCRIPT_LANGUAGE they are using.
Which would be reasons enough for me to not engage any further in here.
But you posted here and the thread will now foerever turn up under "Posted".
Dang.
Offline
He could report is post for deletion, but we can also just wait and see what the OP actually meant.
Unless somebdy can parse their statement, 'cause I've really no exact idea about the issue.
Offline
A very insecure way is:
echo password | sudo -S pacman -S pkg
Ryzen 5900X 12 core/24 thread - RTX 3090 FE 24 Gb, Asus B550-F Gaming MB, 128Gb Corsair DDR4, Cooler Master N300 chassis, 5 HD (2 NvME PCI, 4SSD) + 1 x optical.
Linux user #545703
/ is the root of all problems.
Offline
Given that it has "main commands" but just not installing/removing, I'm inclined to agree with Schard's interpretation as surely updating would be one of the main commands (and this requires sudo / root).
But in any case, pikomarco, please post the actual code. Even without any language barrier, describing what a script does is error prone - show us the script, and we'll see exactly what it does.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
But in any case, pikomarco, please post the actual code. Even without any language barrier, describing what a script does is error prone - show us the script, and we'll see exactly what it does.
Right!
The script is this:
#! /bin/bash
2 while true
3 do
4 echo "=========="
5 echo "Pac-Man"
6 echo "=========="
echo "1) update "
8echo "2) pacchetti installati "
9 echo "3) pulisci l'intera cache "
19 echo e "\n"
11 echo "Premi u per uscire "
12 echo -e "\n"
13 echo -e "Scegli: \c"
14 read answer
15 case "$answer" in
16 1) sudo pacman -Syu ;;
2) pacman -Q ;;
20 3) sudo pacman -Scc ;;
22 u)exit ;;
23 esac
24 echo -e "Premi INVIO per tornare al menù \c"
25 read input
26 done
The options is an italian.
Last edited by pikomarco (2023-01-18 07:48:31)
Offline
Ok, but that doesn't explain what your problem is - it's an interactive script, there's no input redirection… so where's the problem?
Offline
Okay, here is the deal: pikomarco wants to add names of packages to commands like "pacman -S" and doesn't know enough bash. Now he's come here for input, but we don't get it, because the question is so basic, that we should be discussing basic bash guides.
Offline
Formatted so one can read it.
#! /bin/bash
while true; do
echo "=========="
echo "Pac-Man"
echo "=========="
echo "1) update "
echo "2) pacchetti installati "
echo "3) pulisci l'intera cache "
echo e "\n"
echo "Premi u per uscire "
echo -e "\n"
echo -e "Scegli: \c"
read answer
case "$answer" in
sudo pacman -Syu ;;
pacman -Q ;;
sudo pacman -Scc ;;
u)exit ;;
esac
echo -e "Premi INVIO per tornare al menù \c"
read input
done
And that has multiple problems.
How about something like this framework:
#!/usr/bin/bash
PS3="
Select an option.: "
while :; do
clear
options=("Quit" "update" "pacchetti installati" "pulisci l'intera cache")
select opt in "${options[@]}"; do
case "$opt" in
Quit) clear; exit
;;
update) echo "pacman -Syu"
break
;;
"pacchetti installati") echo "pacman -Q"
break
;;
"pulisci l'intera cache") echo "pacman -Scc"
break
;;
*) echo "Not a valid option"
break
;;
esac
done
sleep 2
done
Last edited by teckk (2023-01-18 20:27:24)
Offline
He has proper case handling (gets lost in the broken and somewhat inconsistent line handling)
The script is certainly improvable on multiple layers and in multiple regards, but I'm afraid that schard and Awebb are correct (at least their parsing doesn't contradict the statement - absurd as it seems since the existing script reads and references variables …)
Offline
/me turns to ChatGPT to write a pacman wrapper...
Offline
Hi all,
i risolved with
#! /bin/bash
while true
do
echo "==============="
echo " Pac-Man "
echo "==============="
echo "1) Installa"
echo "2) Rimuovi"
echo "3) Pacchetti installati"
echo "4) Pulisce l'intera cache"
echo -e "\n"
echo "Premi u per uscire "
echo -e "\n"
read -p "Scegli: " answer
case "$answer" in
1) clear
read -p "Nome del pacchetto da installare: " pkg
sudo pacman -S $pkg
clear
continue
;;
2) clear
read -p "Nome del pacchetto da rimuovere: " pkg
sudo pacman -Rs $pkg
clear
continue
;;
3) pacman -Q ;;
4) sudo pacman -Scc ;;
u) exit ;;
*) clear
continue
esac
done
It's not a greatest script but is pratical for me.
Thanks all!
Last edited by pikomarco (2023-01-20 08:29:29)
Offline