You are not logged in.
Hello.
I want to write a shell script (it can be bash,sh,ksh,csh or zsh) that will be:
1.Read unhashed lines from file named mirrors.conf.
2.Put them in ~/.profile as PKG_PATH=line catted from mirrors.conf.
Just like as mirrors.conf file for pacman.
Now it can cat lines but how to put them in files as PKG_PATH?
Thanks for answers.
Last edited by SpeedVin (2010-03-01 17:33:20)
Shell Scripter | C/C++/Python/Java Coder | ZSH
Offline
try:
{kitty|~}$ sed -n '/^#\|^$/d; s/^Server = /PKG_PATH=/p' /etc/pacman.d/mirrorlist
PKG_PATH=ftp://mirror.giantix-server.de/archlinux/$repo/os/i686
using the mirrorlist as an example.
/etc/rc.d/ is where daemons reside. Beware.
Offline
try:
{kitty|~}$ sed -n '/^#\|^$/d; s/^Server = /PKG_PATH=/p' /etc/pacman.d/mirrorlist PKG_PATH=ftp://mirror.giantix-server.de/archlinux/$repo/os/i686
using the mirrorlist as an example.
FYI: You don't need the -n flag or the 'p' modifier at the end of your s/// command.
Offline
grep -v '^#\|^$' /etc/pacman.d/mirrorlist | while read mirror; do echo "${mirror/Server = /PKG_PATH=}" >> ~/.profile done
i hate sed .
That will mess with the whitespace. Maybe for the intended use that doesn't matter. If it did matter, you'd want to adjust that to:
... | while IFS= read -r mirror; do
....
done
Offline
^ IFS is not necessary here; it won't mess with the white space:
$ echo 'args with formatted spaces ' | while read -r; do echo "$REPLY"; done
args with formatted spaces
Offline
Add this line to ~/.profile:
PKG_PATH=$(awk '/^Server/ { print $3; exit }' /etc/pacman.d/mirrorlist)
Note: You can also use `...` instead of $(...).
This way you don't have to do anything when mirrorlist changes.
Offline
^ IFS is not necessary here; it won't mess with the white space:
$ echo 'args with formatted spaces ' | while read -r; do echo "$REPLY"; done args with formatted spaces
It matters for leading/trailing whitespace:
$ echo ' after some ' | while read -r line; do echo "<$line>"; done
<after some>
$ echo ' after some ' | while IFS= read -r line; do echo "<$line>"; done
< after some >
Offline
Thank you all for answers I can't use sed then I used brishbin33 script
Kitty: I like your script and I think that I will learn Sed
Shell Scripter | C/C++/Python/Java Coder | ZSH
Offline