On Wed, Aug 14, 2013 at 6:05 PM, Vadim Zhukov <persg...@gmail.com> wrote: > 2013/8/15 Andres Perera <andre...@zoho.com>: >> On Wed, Aug 14, 2013 at 5:15 AM, Vadim Zhukov <persg...@gmail.com> wrote: >>> + p) >>> + set -f >>> + if [ "${PWD##$OPTARG}" == "${PWD}" ]; then >>> + cat >&2 <<EOE >>> +${0##*/}: current directory does not seem to be under the >>> +specified root directory: $OPTARG >>> +EOE >>> + exit 3 >>> + fi >>> + set +f >> >> there's no need to toggle ``noglob'' >> >> use ${PWD##"$OPTARG"} to suppress the globbing in the RHS of ``##'' > > Nice idea, thanks! I was thinking that it won't work in all cases, but > see below. :) > >>> +if [[ -z $portsdir ]]; then >>> + set +e >>> + portsdir=$(make -V PORTSDIR 2>/dev/null) >>> + (($? == 0)) && portsdir= >>> + set -e >>> +fi >> >> there's no need to toggle ``errexit'' >> >> use portsdir=$(make -V PORTSDIR 2>/dev/null) && portsdir= > > Another nice trick, thanks again!
the alternate form also exposes what i believe to be a logic bug i think you meant to use: portsdir=$(make -V PORTSDIR 2>/dev/null) || portsdir= ie logical OR instead of logical AND, so that you retain the output of `make -VPORTSDIR`, and avoid using heuristics further on > >> if the LHS of ``&&'' fails, the shell won't exit even if ``errexit'' >> is under effect >> >>> + >>> +if [[ -z $portsdir ]]; then >>> + # heuristics mode ON >>> + pkgpath="${PWD##*/ports/*(mystuff/|openbsd-wip/|p5-ports-wip/)}" >> >>> + set -f >>> + portsdir="${PWD%/$pkgpath}" >>> + set +f >> >> same as previous unnecessary ``noglob'' toggling > > I thought that this wouldn't work here, because we already have double > quotes around - but looks like they are not needed at all. At least, > ksh does not do field splitting or glob expansion of $b in a=$b > case... So a quiet a few double quotes could be dropped now. Thanks > again! ksh performs file name matching in the RHS of a parameter expansion operator, *even during assignment* /tmp/t $ touch foobar /tmp/t $ v=foobar /tmp/t $ g='foo???' /tmp/t $ x=${v#"$g"} /tmp/t $ echo "($x)" (foobar) /tmp/t $ x=${v#$g} /tmp/t $ echo "($x)" () > >>> + set -f >>> + pkgpath="${PWD##$portsdir/}" >>> + set +f >> >> same as previous unnecessary ``noglob'' toggling > > yep. > > -- > WBR, > Vadim Zhukov >