FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Gentoo > Gentoo Development

 
 
LinkBack Thread Tools
 
Old 10-01-2010, 01:34 PM
Thomas Sachau
 
Default gentoo-x86 commit in net-misc/openvpn: ChangeLog openvpn-2.1.3.ebuild

Am 01.10.2010 15:07, schrieb Peter Volkov:
> В Пнд, 27/09/2010 в 11:37 +0000, Dirkjan Ochtman (djc) пишет:
>
>> [[ ${i} == "README" || ${i} == "examples" || ${i} == "defer" ]] && continue
>> [[ ${i} == "auth-pam" ]] && ! use pam && continue
>> einfo "Building ${i} plugin"
>> cd "${i}"
>> emake CC=$(tc-getCC) || die "make failed"
>> cd ..
>
> I think pushd/popd are better suited for this then cd "${dir}" / cd ..
>

You can make it even shorter by using the -C switch of (e)make, so you dont have to manually
enter/exit the dir.

--
Thomas Sachau

Gentoo Linux Developer
 
Old 10-01-2010, 03:17 PM
Nirbheek Chauhan
 
Default gentoo-x86 commit in net-misc/openvpn: ChangeLog openvpn-2.1.3.ebuild

On Fri, Oct 1, 2010 at 6:37 PM, Peter Volkov <pva@gentoo.org> wrote:
> В Пнд, 27/09/2010 в 11:37 +0000, Dirkjan Ochtman (djc) пишет:
>> src_compile() {
>> * * * use static && sed -i -e '/^LIBS/s/LIBS = /LIBS = -static /' Makefile
>>
>> * * * emake || die "make failed"
>>
>> * * * if ! use minimal ; then
>> * * * * * * * cd plugin
>> * * * * * * * for i in $( ls 2>/dev/null ); do
>
> This is bad construction:
> http://mywiki.wooledge.org/BashPitfalls#for_i_in_.24.28ls_.2A.mp3.29
>

A nice way around this is to do the following:

ls -1 | while read i; do

`read` delimits on newline, so you're safe.

--
~Nirbheek Chauhan

Gentoo GNOME+Mozilla Team
 
Old 10-02-2010, 03:38 AM
Ryan Hill
 
Default gentoo-x86 commit in net-misc/openvpn: ChangeLog openvpn-2.1.3.ebuild

On Fri, 1 Oct 2010 20:47:38 +0530
Nirbheek Chauhan <nirbheek@gentoo.org> wrote:

> On Fri, Oct 1, 2010 at 6:37 PM, Peter Volkov <pva@gentoo.org> wrote:
> > В Пнд, 27/09/2010 в 11:37 +0000, Dirkjan Ochtman (djc) пишет:
> >> src_compile() {
> >> * * * use static && sed -i -e '/^LIBS/s/LIBS = /LIBS = -static /' Makefile
> >>
> >> * * * emake || die "make failed"
> >>
> >> * * * if ! use minimal ; then
> >> * * * * * * * cd plugin
> >> * * * * * * * for i in $( ls 2>/dev/null ); do
> >
> > This is bad construction:
> > http://mywiki.wooledge.org/BashPitfalls#for_i_in_.24.28ls_.2A.mp3.29
> >
>
> A nice way around this is to do the following:
>
> ls -1 | while read i; do
>
> `read` delimits on newline, so you're safe.

This strips leading and trailing whitespace.

$ touch " test1"
$ touch "test2 "
$ touch "test 3"
$ touch " test 4 "

$ ls -1 | while read i; do echo "###${i}###"; done
###test2###
###test 3###
###test1###
###test 4###

instead use:

$ ls -1 | while IFS= read i; do echo "###${i}###"; done
###test2 ###
###test 3###
### test1###
### test 4 ###

or recursively:

$ find . -type f -print0
| while IFS= read -d $'' i; do echo "###${i}###"; done
###./ test1###
###./ test 4 ###
###./test 3###
###./test2 ###

or just make things simple on yourself

$ for i in *; do echo "###${i}###"; done
### test1###
###test2 ###
###test 3###
### test 4 ###


--
fonts, gcc-porting, we hold our breath, we spin around the world
toolchain, wxwidgets you and me cling to the outside of the earth
@ gentoo.org EFFD 380E 047A 4B51 D2BD C64F 8AA8 8346 F9A4 0662
 
Old 10-02-2010, 12:32 PM
Nirbheek Chauhan
 
Default gentoo-x86 commit in net-misc/openvpn: ChangeLog openvpn-2.1.3.ebuild

On Sat, Oct 2, 2010 at 9:08 AM, Ryan Hill <dirtyepic@gentoo.org> wrote:
> On Fri, 1 Oct 2010 20:47:38 +0530
> Nirbheek Chauhan <nirbheek@gentoo.org> wrote:
>>
>> A nice way around this is to do the following:
>>
>> * * ls -1 | while read i; do
>>
>> `read` delimits on newline, so you're safe.
>
> This strips leading and trailing whitespace.
>
> $ touch " test1"
> $ touch "test2 "
> $ touch "test 3"
> $ touch " test 4 "
>
> $ ls -1 | while read i; do echo "###${i}###"; done
> ###test2###
> ###test 3###
> ###test1###
> ###test 4###
>

Damn, I never knew that.

> instead use:
>
> $ ls -1 | while IFS= read i; do echo "###${i}###"; done
> ###test2 ###
> ###test 3###
> ### test1###
> ### test 4 ###
>
> or recursively:
>
> $ find . -type f -print0
> *| while IFS= read -d $'' i; do echo "###${i}###"; done
> ###./ test1###
> ###./ test 4 ###
> ###./test 3###
> ###./test2 ###
>
> or just make things simple on yourself
>
> $ for i in *; do echo "###${i}###"; done
> ### test1###
> ###test2 ###
> ###test 3###
> ### test 4 ###
>

I wonder how many scripts I wrote now have this subtle bug. Thanks!

--
~Nirbheek Chauhan

Gentoo GNOME+Mozilla Team
 
Old 10-05-2010, 04:20 AM
Jeroen Roovers
 
Default gentoo-x86 commit in net-misc/openvpn: ChangeLog openvpn-2.1.3.ebuild

On Fri, 1 Oct 2010 20:47:38 +0530
Nirbheek Chauhan <nirbheek@gentoo.org> wrote:

> >> * * * * * * * for i in $( ls 2>/dev/null ); do

[...]

> A nice way around this is to do the following:
>
> ls -1 | while read i; do

What pva carelessly omitted to point out was that using ls(1) is
incredibly bad bash programming, which is probably why stderr is being
redirected in this case, too.


jer
 
Old 10-12-2010, 08:09 PM
Dirkjan Ochtman
 
Default gentoo-x86 commit in net-misc/openvpn: ChangeLog openvpn-2.1.3.ebuild

On Fri, Oct 1, 2010 at 15:07, Peter Volkov <pva@gentoo.org> wrote:
> [a very thorough review of the openvpn ebuild]

Thanks for reviewing, I've fixed most of the issues.

>> if [[ -n $(ls /etc/openvpn/*/local.conf 2>/dev/null) ]] ; then
>
> I'd suggested [ -e /etc/openvpn/*/local.conf ] here, but probably there
> are better alternatives. Also ${ROOT} is missed here.

I've put ${ROOT} in, are there no better alternatives? I don't think
anyone mentioned any.

Cheers,

Dirkjan
 
Old 10-12-2010, 08:17 PM
Mike Frysinger
 
Default gentoo-x86 commit in net-misc/openvpn: ChangeLog openvpn-2.1.3.ebuild

On Tuesday, October 12, 2010 16:09:06 Dirkjan Ochtman wrote:
> On Fri, Oct 1, 2010 at 15:07, Peter Volkov wrote:
> >> if [[ -n $(ls /etc/openvpn/*/local.conf 2>/dev/null) ]] ; then
> >
> > I'd suggested [ -e /etc/openvpn/*/local.conf ] here, but probably there
> > are better alternatives. Also ${ROOT} is missed here.
>
> I've put ${ROOT} in, are there no better alternatives? I don't think
> anyone mentioned any.

[ -e ] will break with multiple files (which is the whole point of the glob ?)

you could use find, but that doesnt really seem any better than the ls (which
btw will spill errors if no local.conf exists):
find "${ROOT}"/etc/openvpn/*/ -maxdepth 1 -name local.conf >/dev/null
-mike
 
Old 10-12-2010, 08:26 PM
Jeroen Roovers
 
Default gentoo-x86 commit in net-misc/openvpn: ChangeLog openvpn-2.1.3.ebuild

On Tue, 12 Oct 2010 22:09:06 +0200
Dirkjan Ochtman <djc@gentoo.org> wrote:

> On Fri, Oct 1, 2010 at 15:07, Peter Volkov <pva@gentoo.org> wrote:
> > [a very thorough review of the openvpn ebuild]
>
> Thanks for reviewing, I've fixed most of the issues.
>
> >> if [[ -n $(ls /etc/openvpn/*/local.conf 2>/dev/null) ]] ;
> >> then
> >
> > I'd suggested [ -e /etc/openvpn/*/local.conf ] here, but probably
> > there are better alternatives. Also ${ROOT} is missed here.
>
> I've put ${ROOT} in, are there no better alternatives? I don't think
> anyone mentioned any.

for foo in ${ROOT}/etc/openvpn/*/local.conf; do
[ -e ${foo} ] && bar ${foo}
done

If no ${ROOT}/etc/openvpn/*/local.conf is found, it returns the exact
string; which doesn't exist so Nothing Happens.


jer
 
Old 10-12-2010, 08:57 PM
Mike Frysinger
 
Default gentoo-x86 commit in net-misc/openvpn: ChangeLog openvpn-2.1.3.ebuild

On Tuesday, October 12, 2010 16:26:31 Jeroen Roovers wrote:
> On Tue, 12 Oct 2010 22:09:06 +0200 Dirkjan Ochtman wrote:
> > On Fri, Oct 1, 2010 at 15:07, Peter Volkov wrote:
> > > [a very thorough review of the openvpn ebuild]
> >
> > Thanks for reviewing, I've fixed most of the issues.
> >
> > >> if [[ -n $(ls /etc/openvpn/*/local.conf 2>/dev/null) ]] ;
> > >>
> > >> then
> > >
> > > I'd suggested [ -e /etc/openvpn/*/local.conf ] here, but probably
> > > there are better alternatives. Also ${ROOT} is missed here.
> >
> > I've put ${ROOT} in, are there no better alternatives? I don't think
> > anyone mentioned any.
>
> for foo in ${ROOT}/etc/openvpn/*/local.conf; do
> [ -e ${foo} ] && bar ${foo}
> done
>
> If no ${ROOT}/etc/openvpn/*/local.conf is found, it returns the exact
> string; which doesn't exist so Nothing Happens.

i'd say doing a loop is worse than a `ls` hack. and this has quoting
problems, but that's ancillary ...
-mike
 
Old 10-13-2010, 07:08 AM
Vaeth
 
Default gentoo-x86 commit in net-misc/openvpn: ChangeLog openvpn-2.1.3.ebuild

Mike Frysinger wrote:

> > for foo in ${ROOT}/etc/openvpn/*/local.conf; do
> > [ -e ${foo} ] && bar ${foo}
> > done
>
> i'd say doing a loop is worse than a `ls` hack.

Why do you think so? No external program on which you must rely,
and if you put a "break" in there, the loop is just syntactical.
Here is another possibility if you do not need positional
parameters anymore:

set -- "${ROOT}"/etc/openvpn/*/local.conf
if test -e "${1}"
then ...
fi

And if you do need, you can write a function:

Test2() {
test "${1}" "${2}"
}

if Test2 -e "${ROOT}"/etc/openvpn/*/local.conf
then ...
fi
 

Thread Tools




All times are GMT. The time now is 08:01 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org