View previous topic :: View next topic |
Author |
Message |
tody4 n00b
Joined: 13 Sep 2005 Posts: 53
|
Posted: Fri Mar 03, 2006 4:17 pm Post subject: Learning to bash - unmasking script |
|
|
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 |
|
|
Unne l33t
Joined: 21 Jul 2003 Posts: 616
|
Posted: Fri Mar 03, 2006 4:26 pm Post subject: |
|
|
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 |
|
|
Earthwings Bodhisattva
Joined: 14 Apr 2003 Posts: 7753 Location: Germany
|
Posted: Fri Mar 03, 2006 4:33 pm Post subject: |
|
|
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 |
|
|
tody4 n00b
Joined: 13 Sep 2005 Posts: 53
|
Posted: Fri Mar 03, 2006 4:39 pm Post subject: [solved] |
|
|
That's what it was, thanks for the help. |
|
Back to top |
|
|
sparks Guru
Joined: 05 Mar 2003 Posts: 331 Location: Nashville, TN
|
Posted: Sat Mar 04, 2006 7:42 pm Post subject: Re: Learning to bash - unmasking script |
|
|
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 |
|
|
|