You are not logged in.
Pages: 1
Hi All,
i've been trying to help out with the Archbang Project and come up with this little script only problem is it doesn't work as inteneded.
What i'm trying to-do is make sure the script can access the files it needs where ever it's run from .
#!/bin/bash
if [ "$1" = "clean" ]; then
echo $(pwd)
rm -v $(pwd)/../overlay/src/pkgs/*.tar.*
exit 1
fi
exec < $(pwd)/../overlay/src/pkgs/packages.extra
while read package
do
pkgs=$(echo "$pkgs $package")
done
echo "fetching $pkgs"
pacman -d -Sw --noconfirm --cachedir $(pwd)/../overlay/src/pkgs $pkgs
i know about pwd and $0 for getting paths but wasn't sure the best way round making sure the script can find the files.
Anyone got any suggestions or links to some helpfull material i have done a google search but wasn't quiet sure how to word what i was doing.
Regards
Matthew
"is adult entertainment killing our children or is killing our children entertaining adults?" Marilyn Manson
Offline
http://tldp.org/LDP/abs/html/
http://mywiki.wooledge.org/BashFAQ
I can recommend that the central while/read loop be rewritten as:
IFS=$'\n' read -r -d $'\0' -a pkgs < "$PWD/../overlay/src/pkgs/packages.extra"
This leaves you with an array, so you'll then need to change the pacman execution slightly to:
pacman -Sdw --noconfirm --cachedir "$PWD/../overlay/src/pkgs" "${pkgs[@]}"
Relative paths is probably a bad idea. If you have a way to confirm at some point that a relative path is pointing to a correct location, save that. In other words, suppose at some point you're sure that the path "$PWD/../overlay/src" is known good. Save that as, for example, $absrcroot and then you can reference $absrcroot/pkgs instead of banking on your working directory not changing.
Also, as a general rule of thumb for variables: always double quote them unless you're without a doubt absolutely sure that no white space could ever exist in them. If you're not sure, quote it.
Last edited by falconindy (2010-05-07 11:33:50)
Offline
thank you i will try that shortly
Learning something new today
"is adult entertainment killing our children or is killing our children entertaining adults?" Marilyn Manson
Offline
kk just so i understand this i had an idea of checking the out of $0 and PWD to work out where the script is
one of the 2 will have to contain the path to the script and therfore the project.
very crude but something like
if len $0 <1 then
check and use PWD instead
is that kinda what you where getting at?
Regards
Matthew
Last edited by genisis300 (2010-05-07 16:43:34)
"is adult entertainment killing our children or is killing our children entertaining adults?" Marilyn Manson
Offline
Pages: 1