Fedora Linux Support Community & Resources Center
Old 10th November 2012, 12:35 AM
Ihatewindows Offline
Join Date: Oct 2012
Location: Fort Wayne, IN
Posts: 1,133
Bad shell script code??

Hi, I was making a shell script to install the RPM Fusion repository and install mp3/mp4 codecs when I ran into a problem. It says that "sudo yum install gstreamer-plugins bad;sudo yum install gstreamer-plugins-ugly is an ivalid command, so I copy/pase it into the terminal, and lo and behold, it works. Here's my code that I made up in Emacs:
#RPM Fusion installer script
echo "Welcome to the RPM Fusion installer script. The first thing we will do is 
to update your system. You may be prompted for a password."
read -n1 -r -p "Press ENTER to update..." key ENTER
sudo yum upgrade
echo "Now you are ready to install the RPM Fusion repository."
read -n1 -r -p "Press ENTER to download and install the RPM Fusion repository..." key ENTER
sudo rpm -ivh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm
sudo rpm -ivh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
#finishing the install with a question
while true; do
    read -p "Do you want to install mp3 and mp4 codecs? (Y/N)" yn
    case $yn in
        [Yy]* ) "sudo yum install gstreamer-plugins-bad;sudo yum install gstreamer-plugins-ugly"; break;;
        [Nn]* ) exit;;
        * ) echo "Please answer Y/N, or press <CTRL>+<C> to quit.";;
echo "You're done!"
read -n1 -r -p "Press ENTER to exit..." key ENTER
Any help is appreciated! Thanks!
Reply With Quote
Old 10th November 2012, 01:04 AM
glennzo Online
Un-Retired Administrator
Join Date: Mar 2004
Location: In your closet
Posts: 15,550
Re: Bad shell script code??

Remove the quotes from this line.
PHP Code:
"sudo yum install gstreamer-plugins-bad;sudo yum install gstreamer-plugins-ugly"; break;; 
Actually, you could change the line to
PHP Code:
sudo yum install gstreamer-plugins-bad gstreamer-plugins-ugly; break;; 
No need to call yum twice. I think you should run the whole script with permissions instead of entering passwords several times.

This would be my take on your script. You would only need to enter sudo password once.
PHP Code:
#RPM Fusion installer script

# Need root permissions
if [[ $EUID -ne 0 ]] ; then
echo "Need root permissions to execute this script."
exit 1

echo "Welcome to the RPM Fusion installer script. The first thing we will do is 
to update your system. You may be prompted for a password."
read -n1 --"Press ENTER to update..." key ENTER
yum upgrade
echo "Now you are ready to install the RPM Fusion repository."
read -n1 --"Press ENTER to download and install the RPM Fusion repository..." key ENTER
-ivh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm
rpm -ivh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
#finishing the install with a question
while true; do
read -"Do you want to install mp3 and mp4 codecs? (Y/N)" yn
case $yn in
[Yy]* ) yum install gstreamer-plugins-bad gstreamer-plugins-ugly; break;;
Nn]* ) exit;;
        * ) echo 
"Please answer Y/N, or press <CTRL>+<C> to quit.";;
echo "You're done!"
read -n1 --"Press ENTER to exit..." key ENTER
So to run the script you would execute
PHP Code:
sudo sh script.sh 
Maybe the rpmfusion install line from the rpmfusion web site would be more appropriate.
PHP Code:
yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm 
The Bassinator
© ®
Reply With Quote
Old 10th November 2012, 01:13 AM
sea Offline
"Shells" (of a sub world)
Join Date: May 2011
Location: Confoederatio Helvetica (Swissh)
Age: 37
Posts: 4,277
Re: Bad shell script code??

You could actualy 'parse' the users input and add it up to a list which will be installed only once.

sudo rpm -ivh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm \

read -p "want add mp3/mp4 codecs? (y/n)" -n1 ANSWER

[ "y" = "$ANSWER" ] && \
	list="gstreamer-plugins-bad gstreamer-plugins-ugly" || \

[ ! "" = "$list" ] && \
	sudo yum install -y $list
For my taste this list is a bit short, as i'd want more out of these packages.
You might want to have a view at my script:
EFI Cheatsheet :: http://forums.fedoraforum.org/showthread.php?t=298546
Video Handler Script (VHS) (mass re-encode videos, screenrecorder, console music/webradio player, ...) :: http://forums.fedoraforum.org/showthread.php?t=299182
Windows 8+ & Fedora 20+ Dualboot :: http://forums.fedoraforum.org/showthread.php?t=298161

Last edited by sea; 10th November 2012 at 01:21 AM.
Reply With Quote
Old 10th November 2012, 01:22 AM
Ihatewindows Offline
Join Date: Oct 2012
Location: Fort Wayne, IN
Posts: 1,133
Re: Bad shell script code??

The permissions check is actually a really good idea. I'm still kinda new to Linux (only been using it for about a year and a half.) I'm gonna make a cheat sheet. Thanks!
Reply With Quote

bad, code, emacs, script, shell

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP script won't render in browser - just displays the code mickburkejnr Servers & Networking 1 11th August 2012 07:56 PM
call remote shell script within an expect script PhillyFloyd Programming & Packaging 2 16th October 2007 10:29 PM
starting a shell script inside a php script gw348 Using Fedora 6 23rd April 2007 09:30 PM
shell script Wangberg Programming & Packaging 13 4th April 2007 04:48 PM
need to run script Bourne-shell script armen Using Fedora 4 4th April 2005 01:16 PM

Current GMT-time: 16:51 (Tuesday, 22-08-2017)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat