zsh-users
 help / color / mirror / code / Atom feed
* passing parameters
@ 2005-05-05 21:42 zzapper
  2005-05-06  3:57 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: zzapper @ 2005-05-05 21:42 UTC (permalink / raw)
  To: zsh-users

Hi

I have a script which as follows which works fine (where ftx is going to search for tex docs with
pink & main in the name) 

>ftx "pink.*main"

however I thought I'd convert it so that i could write

> ftx pink main

and then rebuild "pink.*main" string inside the function however it doesn't seem to work

param="$1.*$2"

$param is not treated the same as the original $1


-- 
zzapper
vim -c ":%s%s*%Cyrnfr)fcbafbe[Oenz(Zbbyranne%|:%s)[[()])-)Ig|norm Vg?"
http://www.rayninfo.co.uk/tips/ vim, zsh & success tips


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: passing parameters
  2005-05-05 21:42 passing parameters zzapper
@ 2005-05-06  3:57 ` Bart Schaefer
  2005-05-06 12:54   ` zzapper
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2005-05-06  3:57 UTC (permalink / raw)
  To: zsh-users

On May 5, 10:42pm, zzapper wrote:
}
} I have a script which as follows which works fine (where ftx is going
} to search for tex docs with pink & main in the name)
} 
} >ftx "pink.*main"

That looks like a regular expression rather than a glob pattern?
 
} param="$1.*$2"
} 
} $param is not treated the same as the original $1

Er, "not treated the same" how?  There's nowhere near enough context
here for anything useful to be said.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: passing parameters
  2005-05-06  3:57 ` Bart Schaefer
@ 2005-05-06 12:54   ` zzapper
  2005-05-06 16:03     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: zzapper @ 2005-05-06 12:54 UTC (permalink / raw)
  To: zsh-users

On Fri, 06 May 2005 03:57:34 +0000,  wrote:


>
>Er, "not treated the same" how?  There's nowhere near enough context
>here for anything useful to be said.
Sorry Bart
Turns out it's nowt to do with passing parameters (I give two versions of the same script)

So if I want to edit a tex file somewhere in a file tree which has got say "family" as part of it's
file name I type

> ftx family

maybe however there's more than one file so I type a "regexp" such

> ftx "family.*tree"

That works fine, so then I think lets pass the "regexp" as two parameters to save a bit of typing

> ftx family tree
However that's where I run into trouble
with
param="$1.*$2"

but use of $param breaks the following script

ftx () {
        if [ $# -gt 0 ]
        then
                cd /c/intranet/latex/
                cnt=$(ls **/*.tex |egrep -ic "$1[^/]*.tex" )
                texfile=$(ls **/*.tex |egrep -i "$1[^/]*.tex" )
                if [ $cnt -eq 1 ]
                then
                        gvim.exe $texfile
                else
                        echo $texfile
                fi
        else
                echo please enter a keyword to search for tex file
        fi
}

SO I HAVE TO WRITE $param AS ${param} IN FOLLOWING WORKING SCRIPT

function ftx()
{
if [ $# -gt 0 ] 
then
if [ $# -gt 1 ] 
then
param="$1.*$2"
else
param=$1
fi
cd /c/intranet/latex/
cnt=$(ls **/*.tex |egrep -ic "${param}[^/]*.tex" )
texfile=$(ls **/*.tex |egrep -i "${param}[^/]*.tex" )
if [ $cnt -eq 1 ]
then
gvim.exe $texfile
else
echo $texfile
fi
else
echo please enter a keyword to search for tex file
fi
}

But why is it necessary to write ${param} ? and it wasn't necessary to write  ${1}


-- 
zzapper
vim -c ":%s%s*%Cyrnfr)fcbafbe[Oenz(Zbbyranne%|:%s)[[()])-)Ig|norm Vg?"
http://www.rayninfo.co.uk/tips/ vim, zsh & success tips


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: passing parameters
  2005-05-06 12:54   ` zzapper
@ 2005-05-06 16:03     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2005-05-06 16:03 UTC (permalink / raw)
  To: zsh-users

On May 6,  1:54pm, zzapper wrote:
>
>                 cnt=$(ls **/*.tex |egrep -ic "$1[^/]*.tex" )
>                 texfile=$(ls **/*.tex |egrep -i "$1[^/]*.tex" )

[versus]

> param="$1.*$2"
> cnt=$(ls **/*.tex |egrep -ic "${param}[^/]*.tex" )
> texfile=$(ls **/*.tex |egrep -i "${param}[^/]*.tex" )
> 
> But why is it necessary to write ${param} ? and it wasn't necessary to
> write ${1}

$identifier[subscript] is an array expression.  When $identifier is a
scalar, it does character-wise indexing to extract substrings.

"1" is not an identifier.  $1 is a special case of expansion used for
the positional parameters.  So $1[anything] is not an array expression,
it's the expression $1 followed by the string [anything].  Similarly,
$1foo is ${1}foo because "1foo" is not an identifier, but "foo1" is an
identifier so $foo1 is the same as ${foo1}.

You can force indexing into $1 by ${1[subscript]}.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-05-06 16:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-05 21:42 passing parameters zzapper
2005-05-06  3:57 ` Bart Schaefer
2005-05-06 12:54   ` zzapper
2005-05-06 16:03     ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).