You are not logged in.
Pages: 1
Topic closed
Hi, newbie here, trying to learn a bit more about the Arch command line. I am trying to make a script (which I named Scc.sh) where, after I type,
sudo pacman -Scc
the following two prompts would automatically be answered with "yes," but I cannot figure out how to do so; thus far, I have only been successful in getting the first prompt being automatically answered. After trying different methods and reading a few MAN pages, the best I came up with is this:
echo "y" | sudo pacman -Scc \n
echo "Y"
which produces the following output:
[europa@Nemesis ~]$ ./Scc.sh
Cache directory: /var/cache/pacman/pkg/
:: Do you want to remove ALL files from cache? [y/N] y
removing all files from cache...
Database directory: /var/lib/pacman/
:: Do you want to remove unused repositories? [Y/n] Y
[europa@Nemesis ~]$
There is no confirmation in the second prompt of unused sync repositories being removed. However,
sudo pacman -Scc
returns the following output:
[europa@Nemesis ~]$ sudo pacman -Scc
Cache directory: /var/cache/pacman/pkg/
:: Do you want to remove ALL files from cache? [y/N] y
removing all files from cache...
Database directory: /var/lib/pacman/
:: Do you want to remove unused repositories? [Y/n] Y
removing unused sync repositories...
[europa@Nemesis ~]$
Now, I know this may seem like a weird question, so before anyone gets mad and starts insulting me, I'd like to mention that all I am attempting to do is learn/understand the command line more, as I have fell completely in love with Arch since switching over from Ubuntu a couple years back.
Thank you in advance for your help, and have a great day.
"Sometimes you win, sometimes you learn."
Offline
man yes
Also see man pacman (--noconfirm option)
Last edited by amish (2018-04-12 07:21:24)
Offline
man pacman: https://www.archlinux.org/pacman/pacman.8.html
The option --noconfirm suppresses confirmation prompts. The warning says "Bypass any and all “Are you sure?” messages. It’s not a good idea to do this unless you want to run pacman from a script.", which apparently is what you want to do.
Offline
before anyone gets mad and starts insulting me
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline
Maybe check paccache, if your aim is to keep you pacman cache clean.
Offline
the best I came up with is this:
echo "y" | sudo pacman -Scc \n echo "Y"
... all I am attempting to do is learn/understand the command line more.
Then this example can be useful. The difference between the two `echo "y"` commands is that the output of only one of them is sent to the stdin of the pacman command. The second `echo "y"` simply runs on it's own *after* pacman is done and has exited. As a first incremental improvement for instructional purposes, you could do this:
( echo "y"; echo "y" ) | sudo pacman -Scc
This creates a subshell (the parentheses) within which two echo "y" commands are run. The output of that entire subshell is sent to pacman's stdin, so pacman now gets two "y"s in a row which will accomplish what you were trying to do (though I'm making no statement here on whether that is worth doing).
Now creating a subshell just to run two sequential echo commands is a bit silly, so we can get rid of that and just use one echo command that outputs the two "y"s each followed by a newline. This will have the same effect as the example above (also acheiving what you intended to do):
echo -e "y\ny" | sudo pacman -Scc
Now, given that others have realized there may be times where you would just want to generate a string of "y"s followed by newlines to feed as input to another process, a command was created to do just that: it creates a string of "y"s followed by newlines as long as it's output is connected. So this too will do the same as the above:
yes | sudo pacman -Scc
Last edited by Trilby (2018-04-14 11:17:43)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
use pacman -help to view list of commands
pacman -S --help to view options
there you can see --noconfirm
Offline
Please don't necrobump 3 year old topics. Also --noconfirm is explicitly not a solution here since that will answer "No" to prompts where N would be preselected (and has been mentioned two times prior).
Closing.
Offline
Pages: 1
Topic closed