I have a list of packages I want to deinstall. The deinstaller program pkg_deinstall doesn't take a list of packages as parameter to deinstall. How would I deinstall from the list (like a foreach loop)?[root@fbsd01 /usr/ports/editors/vim]# pkg_info | grep proto| sed 's/\([a-z0-9]*\).*/\1/'bigreqsprotocompositeprotodamageprotofixesprotofontsprotoinputprotokbprotorandrprotorenderprotoxcbxcmiscprotoxextprotoxf86bigfontprotoxineramaprotoI would think a command similar to this would work, but I have to pass the list as a parameter and not a stream: pkg_info | grep proto| sed 's/\([a-z0-9]*\).*/\1/' | head -n 1 pkg_deinstallIf you could give me some clues as to what program and syntax to use, that would be helpful. I know since it's unique you might have a hard time coming up with an exact answer. If my question is too complicated, maybe someone could show me how to do actions on an ls of files in a dir.
Doing actions on a list from the shell
bash;shell;freebsd
For the most basic 'foreach' there is xargs, it reads some parameters and append them to some other command line. For example you may try:> cut -d: -f1 /etc/passwd | xargs -n1 echo user:Note that you should pass a -d'\n' argument to xargs in the case usernames could contain space characters.To append all parameters to the same command use:> cut -d: -f1 /etc/passwd | xargs echo users:For more general loops, you can use this:> cut -d: -f1 /etc/passwd | while read i; do echo $i; doneThis time, $i can be placed anywhere in a sequence of one or more commands.Inputs are read one line at a time, and stored in the variable i.It is also possible to split the line and store it in several variables:> cut -d: -f1,6 /etc/passwd --output-delimiter=' ' | \  while read i j; do echo home directory of user $i is $j; doneNote that for loops over raw filenames, the following is better (see comments):> for i in *.txt; do echo file: $i; done1. More precisely: as many as the system will allow.2. According to the IFS variable