3

When I try to run "yum -y update" from a Bash script it doesn't work.

Here is what the script looks like.

#!/usr/bin/
echo "--> Updating CentOS System"
yum -y update

I run the script with this command.

bash script.sh

I get the following output.

Loaded plugins: fastestmirror, refresh-packagekit, security
. Please use /usr/bin/yum --help.

CentOS 6 FINAL Installed via text prompts. I login as root from the text prompt then startx to get into the gui desktop.

But when I run the same command directly in the terminal it works?

I've googled around but not sure if I'm googling the correct terms.

Thanks for your help.

  • chmod u+x script.sh give permission n try or you may run these commands as root user. – Shailesh Oct 10 '13 at 8:55
  • Your hashbang (!#/usr/bin/) is incorrect--it should be something like #!/usr/bin/bash--, but is not relevant to your error since you explicitly run the script with bash. – chepner Oct 10 '13 at 15:13
  • @chepner - Made the change. Getting a weird "Unexpected token" error but the code looks correct. If I run the same script with the bash command it acctualy starts the script without any error. But YUM commands don't seem to work. – cph Oct 14 '13 at 21:16
  • 1
    @Shailesh - Made the changes requested still have issue. – cph Oct 14 '13 at 21:18
  • #! /bin/bash put this line in your script and remove !#/usr/bin/ – Shailesh Oct 22 '13 at 8:33
4

Not sure why your script does not work, but my version worked fine. (I suspect it might be the first line):

#! /bin/bash

echo "--> Updating CentOS System"
yum -y update

Remember to chmod 755 the file, and you can just run it with the file name, no need to prepend it with "bash".

I do note that when I tried to reproduce your problem I couldn't (even though your first line is incorrect the script still worked for me). I wonder if there might have been a hidden typo in the key shell line ? Maybe try deleting it and re-adding it.

  • Did above still seem to be having an issue. Made the change as well. Not sure what's going on here. I'll keep you posted. Thanks for you help. – cph Oct 14 '13 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.