Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Learning to bash - unmasking script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
tody4
n00b
n00b


Joined: 13 Sep 2005
Posts: 53

PostPosted: Fri Mar 03, 2006 4:17 pm    Post subject: Learning to bash - unmasking script Reply with quote

I'm trying to write one of my first bash scripts, taking some information from a post in the Desktop Environments sub-forum, and I can't seem to get it to work for some reason. The output is always the command instead of a list of packages (in this case). Not sure if i'm just not using the variables correctly or what. Any help would be appreciated. Eventually I want to build some intelligence into it so that the script will check the package.keywords / package.unmask file for the current package name and if exists, skip adding to the file, otherwise add to the file, but that's for another time. Right now all I want is for a list of packages to be added to the package.keywords file and I'll write another one to do something similar for package.unmask.

Code:

#! /bin/bash

if [ -z $1 ]; then
   echo "USAGE umask <argument>";
   exit 1
fi

for i in 'emerge -p $1 | grep ebuild \
   | tr -s | cut -f 4';do
   echo "Unmasking Package $i"
#   echo ">=$i ~x86" >> /etc/portage/package.keywords;
done

exit 0

Back to top
View user's profile Send private message
Unne
l33t
l33t


Joined: 21 Jul 2003
Posts: 616

PostPosted: Fri Mar 03, 2006 4:26 pm    Post subject: Reply with quote

You have the command in single quotes, which means the script treats it as a string. You need to put it in backticks ( `` ) so the command is executed.
_________________
Obligatory hompage link.
Back to top
View user's profile Send private message
Earthwings
Bodhisattva
Bodhisattva


Joined: 14 Apr 2003
Posts: 7753
Location: Karlsruhe, Germany

PostPosted: Fri Mar 03, 2006 4:33 pm    Post subject: Reply with quote

Unne wrote:
You have the command in single quotes, which means the script treats it as a string. You need to put it in backticks ( `` ) so the command is executed.

One of the reasons I always use $(command) instead.
_________________
KDE
Back to top
View user's profile Send private message
tody4
n00b
n00b


Joined: 13 Sep 2005
Posts: 53

PostPosted: Fri Mar 03, 2006 4:39 pm    Post subject: [solved] Reply with quote

That's what it was, thanks for the help.
Back to top
View user's profile Send private message
sparks
Guru
Guru


Joined: 05 Mar 2003
Posts: 328
Location: Nashville, TN

PostPosted: Sat Mar 04, 2006 7:42 pm    Post subject: Re: Learning to bash - unmasking script Reply with quote

tody4 wrote:
I'm trying to write one of my first bash scripts, taking some information from a post in the Desktop Environments sub-forum, and I can't seem to get it to work for some reason. The output is always the command instead of a list of packages (in this case). Not sure if i'm just not using the variables correctly or what. Any help would be appreciated. Eventually I want to build some intelligence into it so that the script will check the package.keywords / package.unmask file for the current package name and if exists, skip adding to the file, otherwise add to the file, but that's for another time. Right now all I want is for a list of packages to be added to the package.keywords file and I'll write another one to do something similar for package.unmask.

Code:

#! /bin/bash

if [ -z $1 ]; then
   echo "USAGE umask <argument>";
   exit 1
fi

for i in 'emerge -p $1 | grep ebuild \
   | tr -s | cut -f 4';do
   echo "Unmasking Package $i"
#   echo ">=$i ~x86" >> /etc/portage/package.keywords;
done

exit 0



I like the idea behind this. However I am not a programmer, and could not get this script to work even with the back ticks (``). With my _very_ limited knowledge about bash scripting I tried to make a script that worked for me, this is what I came up with.
Code:

#! /bin/bash
if [ "$UID" -ne "0" ] ; then
   echo "Only root can use this script";
   exit 1
fi

if [ -z $1 ]; then
   echo "USAGE: umask <argument>";
   exit 1
fi

for i in `emerge -p $1 | grep ebuild | cut -b 17-70`
   do echo ">=$i ~amd64 [*Added to packages.keywords*]"
   echo ">=$i ~amd64" >> /etc/portage/package.keywords;
done

exit 0


Now, I'm sure someone is going to say "WTF!? why did you go about it that way?", and honestly its because I don't know any better. If anyone could offer suggestions as how to improve these scripts it would be appreciated.

Also having the intellegence built in to know whether or not a package is already in package.keywords would be nice. Any takers?
_________________
True trade is honest, but not merciful. Politics is dishonest, no matter how merciful... and war is neither honest nor merciful.... therefore, choose trade above politics, but politics above war.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum