You are not logged in.

#1 2006-01-31 08:06:30

mtrivs
Member
From: Syracuse, NY
Registered: 2005-12-26
Posts: 183

shell script help

OK i want to create a shell script to put in /sbin so that when i want to get packages via pacman i can run the script and then it will give me an area to type in.  When i type the package(s) i want it to do a

sudo pacman -Sy X Y Z

(where X Y & Z are package names).  I want to do this more for personal reasons and not really for functionallity......can anyone give me any building blocks/links of things i should start with?


~HP ZV6000 Series CTO~
-AMD Athlon 64 3200+ 2.0GHz
-1.5GB RAM
-128MB ATI Mobility Radeon X200m
-80GB 5400RPM HD
[img]http://imagegen.last.fm/scarface/recenttracks/mtrivs.gif[/img]

Offline

#2 2006-01-31 08:57:27

mtrivs
Member
From: Syracuse, NY
Registered: 2005-12-26
Posts: 183

Re: shell script help

Nevermind...I searched through several sites and found most of the information myself... Here is what i came up with:

#!/bin/sh
echo "Please input the name of the package you want"
read ans
clear
echo "Downloading and installing packages!"
sudo pacman -Sy --noconfirm $ans

~HP ZV6000 Series CTO~
-AMD Athlon 64 3200+ 2.0GHz
-1.5GB RAM
-128MB ATI Mobility Radeon X200m
-80GB 5400RPM HD
[img]http://imagegen.last.fm/scarface/recenttracks/mtrivs.gif[/img]

Offline

#3 2006-01-31 09:07:11

mtrivs
Member
From: Syracuse, NY
Registered: 2005-12-26
Posts: 183

Re: shell script help

I found some more info and developed this (changed it so that if a user enters "x", "q", "exit", or "none", then the script exits!!!!

!/bin/sh
echo "Please input the name of the package you want"
read ans
if [ $ans = "exit" ] || [ $ans = "none" ] || [ $ans = "q" ] || [ $ans = "x" ]
then
         exit
 else
        echo "Downloading and installing packages!"
        sudo pacman -Sy --noconfirm $ans
fi

Shell scripting is great!!!!  lol


~HP ZV6000 Series CTO~
-AMD Athlon 64 3200+ 2.0GHz
-1.5GB RAM
-128MB ATI Mobility Radeon X200m
-80GB 5400RPM HD
[img]http://imagegen.last.fm/scarface/recenttracks/mtrivs.gif[/img]

Offline

#4 2006-01-31 09:24:46

mtrivs
Member
From: Syracuse, NY
Registered: 2005-12-26
Posts: 183

Re: shell script help

ok from my last post i showed you my shell script, but when i type in more than one package it gives me the following error:

/sbin/pak: line 6: [: too many arguments
/sbin/pak: line 6: [: too many arguments
/sbin/pak: line 6: [: too many arguments
/sbin/pak: line 6: [: too many arguments

How can i either fix this or supress this?


~HP ZV6000 Series CTO~
-AMD Athlon 64 3200+ 2.0GHz
-1.5GB RAM
-128MB ATI Mobility Radeon X200m
-80GB 5400RPM HD
[img]http://imagegen.last.fm/scarface/recenttracks/mtrivs.gif[/img]

Offline

#5 2006-01-31 11:05:15

T-Dawg
Forum Fellow
From: Wilmington, NC
Registered: 2005-01-29
Posts: 2,734

Re: shell script help

put it in a for loop

Offline

#6 2006-01-31 11:14:33

mtrivs
Member
From: Syracuse, NY
Registered: 2005-12-26
Posts: 183

Re: shell script help

I know what a for loop is, but where would i put that in....could someone show me an example?


Thanks!


~HP ZV6000 Series CTO~
-AMD Athlon 64 3200+ 2.0GHz
-1.5GB RAM
-128MB ATI Mobility Radeon X200m
-80GB 5400RPM HD
[img]http://imagegen.last.fm/scarface/recenttracks/mtrivs.gif[/img]

Offline

#7 2006-01-31 11:30:02

MAC!EK
Member
Registered: 2005-09-27
Posts: 265

Re: shell script help

replace this:

if [ $ans = "exit" ] || [ $ans = "none" ] || [ $ans = "q" ] || [ $ans = "x" ] 

with that:

if [ "$ans" = "exit" -o "$ans" = "none" -o "$ans" = "q" -o "$ans" = "x" ] 

PS. loop is not needed

Offline

#8 2006-02-01 09:01:43

mtrivs
Member
From: Syracuse, NY
Registered: 2005-12-26
Posts: 183

Re: shell script help

#!/bin/sh
echo "Please input the name of the package(s) you want:"

read ans

if [ "$ans" = "exit" -o "$ans" = "none" -o "$ans" = "q" -o "$ans" = "x" -o "$ans" = "close"]
then
         exit
elif [ $ans = "all" ]
then
                echo "Full system upgrade!"
                sudo pacman -Syu
elif [ $ans = "s" ]
then
        echo "Please enter the name of the package you would like to search for"
        read ans1
                if [ "$ans1" = "exit" -o "$ans1" = "none" -o "$ans1" = "q" -o "$ans1" = "x" -o "$ans" = "close" ]
                then
                        exit
                else
                        sudo pacman -Ss $ans1
                fi
else
                echo "Downloading and installing the packages you requested!"
                sudo pacman -Sy $ans
fi

OK i changed the if statement, but i still get one of these:

/sbin/pak: line 9: [: too many arguments

~HP ZV6000 Series CTO~
-AMD Athlon 64 3200+ 2.0GHz
-1.5GB RAM
-128MB ATI Mobility Radeon X200m
-80GB 5400RPM HD
[img]http://imagegen.last.fm/scarface/recenttracks/mtrivs.gif[/img]

Offline

#9 2006-02-01 09:52:44

postlogic
Member
Registered: 2005-02-24
Posts: 410
Website

Re: shell script help

Wouldnt it be easer to add

alias pacget = "sudo pacman -Sy"

to your .bashrc, and just type pacget X Y Z ?

Instead of trying to reinvent the wheel, I mean.

Although if you do this to learn shellscripting, it's a good way to go ;-)

Offline

#10 2006-02-01 11:21:12

mtrivs
Member
From: Syracuse, NY
Registered: 2005-12-26
Posts: 183

Re: shell script help

Yea i am just trying to learn shell scripts, im not really planning on using this program.... lol


~HP ZV6000 Series CTO~
-AMD Athlon 64 3200+ 2.0GHz
-1.5GB RAM
-128MB ATI Mobility Radeon X200m
-80GB 5400RPM HD
[img]http://imagegen.last.fm/scarface/recenttracks/mtrivs.gif[/img]

Offline

#11 2006-02-01 11:44:44

dust
Member
Registered: 2005-06-04
Posts: 152
Website

Re: shell script help

You may want to put a confirmation request for the whole upgrade all command.


Writing stories for a machine.

Offline

#12 2006-02-01 12:04:06

mtrivs
Member
From: Syracuse, NY
Registered: 2005-12-26
Posts: 183

Re: shell script help

2 questions:
1. what does a confirmation do?
2. how would i implement it into the script?

Thanks for the help guys!!!


~HP ZV6000 Series CTO~
-AMD Athlon 64 3200+ 2.0GHz
-1.5GB RAM
-128MB ATI Mobility Radeon X200m
-80GB 5400RPM HD
[img]http://imagegen.last.fm/scarface/recenttracks/mtrivs.gif[/img]

Offline

#13 2006-02-01 12:12:44

dust
Member
Registered: 2005-06-04
Posts: 152
Website

Re: shell script help

A confirmation statement like:
Upgrading ENTIRE system. Ok to procede(y/n)?_

Dunnos sh but the basic premise is:

define function prompt_for_command(command)
prompt "which packages to install"
 if command == "all"
  prompt "upgrading entire system. ok to procede(y/n)? "
   if y
    run pacman commands
   else
    prompt_for_command()

Personally I'd put in a confirmation for all commands, to ensure you're running what you want to run and isntalling what you want.


Writing stories for a machine.

Offline

#14 2006-02-01 12:18:01

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: shell script help

mtrivs wrote:

OK i changed the if statement, but i still get one of these:

/sbin/pak: line 9: [: too many arguments

Whenever you're comparing $ans to strings, put quotes around it.

elif [ $ans = "all" ]
...
elif [ $ans = "s" ]

should be

elif [ "$ans" = "all" ]
...
elif [ "$ans" = "s" ]

The reason for this is it automatically expands $ans.  If you put in more than one package, then

$ans = X Y Z

and the test becomes

elif [ X Y Z = "all" ]

and, as you can see, it has no idea how to decide what to do with that, since X Y and Z are not in quotes.

Offline

Board footer

Powered by FluxBB