A
A
Anton Misyagin2015-12-06 13:11:12
linux
Anton Misyagin, 2015-12-06 13:11:12

How to apt-get update from a shell script?

sudo apt-get update works fine if run manually, but throws an error when running the script:
sh script.sh

#!/bin/sh
echo "updating"
sudo apt-get update

updating
E: Invalid operation update

uname -a
Linux myserver 3.19.0-25-generic #26~14.04.1-Ubuntu SMP Fri Jul 24 21:18:00 UTC 2015 i686 i686 i686 GNU/Linux

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
moondog, 2015-12-06
@sunnmas

most likely the script is saved in some Windows notepad, which has a line break \r\n
If so, then it sed -i 's/\r//' script.shwill help

R
romy4, 2015-12-06
@romy4

Everything works great. Enable debug #!/bin/sh -x

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question