I have two files, the first one called packages.txt
which is list of packages:
gcc
emacs
vim
python
...
Now, when I run the command
cat packages.txt | tr '\n' ' ' | apt-get install
This basically converts the file into one line of packages separated by space. It does not install all the packages in packages.txt.
(I think it only installs the first one) Does anyone knows why?
Try using xargs
:
xargs -d '\n' -- apt-get install < packages.txt
Or
xargs -d '\n' -n 1 -- apt-get install < packages.txt
Make sure packages.txt
is not in DOS format:
sed -i 's|\r||' packages.txt
The pipe operator sends the stdout
of one application into the next (as stdin
. Unfortunately, apt-get
does not read from stdin
. Rather, apt-get
takes a list of packages on the command line. I think what you are attempting to do is more along the lines of
apt-get install $(cat packages.txt | tr '\n' ' ')
or
apt-get install `cat packages.txt | tr '\n' ' '`
Which is to say evaluate the file list, and pass it in as an arguments to a single apt-get
call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With