zsh-users
 help / color / mirror / code / Atom feed
* stdios confused by a function scope ?
@ 2014-03-20 20:57 Marc Chantreux
  2014-03-21  5:35 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Chantreux @ 2014-03-20 20:57 UTC (permalink / raw)
  To: zsh-users

hello zsh people,

Here is a tmux capture i want to share with you as it completly got me
lost. it seems that a command which works well directly from the
interactive shell is loosing stdin when it is called from a function.

I have no time to investigate for now (and yet, a work around was written and the rt 
function is a fake that just show what is failing) but i really would like to
understand what happened.  

any clue (or ideas for me to investigate) is welcome. 

regards

#### Chapter 1: What we have 

>  print $ZSH_VERSION; which n2/ls n2/asqueue rt fill n2/tk/running
5.0.2
n2/ls () {
        rt ls -s -o Created -q masters "$(  n2/tk/running owner=Nobody )" | n2/asqueue
}
n2/asqueue () {
        sed '1{/^No/Q};s/:/ #/'
}
rt () {
        (
                export RTUSER RTPASSWD RTSERVER RTDEBUG
                 < ~/.uds/rt/credentials | fill RTUSER RTPASSWD RTSERVER
                echo "$@"
        )
}
fill () {
        local garbage
        IFS=$'\n' read -d '' "$@" garbage
}
n2/tk/running () {
        print -f '%s
        and status!=resolved
        and status!=rejected
        and status!=stalled
    ' "$@"
}

#### Chapter 2: the body of n2/ls works fine

> rt ls -s -o Created -q masters "$(  n2/tk/running owner=Nobody )" | n2/asqueue
ls -s -o Created -q masters owner=Nobody
        and status!=resolved
        and status!=rejected
        and status!=stalled

#### Chapter 3: n2/ls is a never ending story

> set -x
> n2/ls
+-zsh:6> n2/ls
+n2/ls:1> n2/tk/running 'owner=Nobody'
+n2/tk/running:1> print -f '%s
        and status!=resolved
        and status!=rejected
        and status!=stalled
    ' 'owner=Nobody'
+n2/ls:3> n2/asqueue
+n2/ls:1> rt ls -s -o Created -q masters 'owner=Nobody
        and status!=resolved
        and status!=rejected
+n2/asqueue:0> sed '1{/^No/Q};s/:/ #/'
        and status!=stalled
    '
+rt:8> export RTUSER RTPASSWD RTSERVER RTDEBUG
+rt:9> fill RTUSER RTPASSWD RTSERVER
+fill:0> local garbage
+fill:0> IFS='
' +fill:0> read -d '' RTUSER RTPASSWD RTSERVER garbage

-- 
Marc Chantreux (eiro on github and freenode)
http://eiro.github.com/
http://eiro.github.com/atom.xml
"Don't believe everything you read on the Internet"
    -- Abraham Lincoln


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

* Re: stdios confused by a function scope ?
  2014-03-20 20:57 stdios confused by a function scope ? Marc Chantreux
@ 2014-03-21  5:35 ` Bart Schaefer
  2014-03-25 10:29   ` Marc Chantreux
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2014-03-21  5:35 UTC (permalink / raw)
  To: zsh-users

On Mar 20,  9:57pm, Marc Chantreux wrote:
} 
} Here is a tmux capture i want to share with you as it completly got me
} lost. it seems that a command which works well directly from the
} interactive shell is loosing stdin when it is called from a function.

Your explanation of what is (not) happening could have been clearer;
I'm still not sure I'm correctly understanding what you expect.

However, this particular construction is very odd:

         < ~/.uds/rt/credentials | fill RTUSER RTPASSWD RTSERVER

This is relying on READNULLCMD to pass the contents of the credentials
file through the pipe to the fill function.  Why would you want to do
that?  Why not simply redirect straight into fill?  You don't even
need to reorder the words (though putting the redirection at the end
would be more typical); just remove the "|" like so:

         < ~/.uds/rt/credentials fill RTUSER RTPASSWD RTSERVER

What is the value of $READNULLCMD ?


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

* Re: stdios confused by a function scope ?
  2014-03-21  5:35 ` Bart Schaefer
@ 2014-03-25 10:29   ` Marc Chantreux
  0 siblings, 0 replies; 3+ messages in thread
From: Marc Chantreux @ 2014-03-25 10:29 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

hello,

On Thu, Mar 20, 2014 at 10:35:36PM -0700, Bart Schaefer wrote:
> Your explanation of what is (not) happening could have been clearer;
> I'm still not sure I'm correctly understanding what you expect.  

well i have to admit i tried (maybe not enough).

fill() is a function used internally by one of the filters of the pipe
and i dont understand why it works when it is used from the command line
but it seems to read forever in some level of function wrapping.

but!

> However, this particular construction is very odd:
> 
>          < ~/.uds/rt/credentials | fill RTUSER RTPASSWD RTSERVER 

damn! not only i wrote this but i read it hundred times without
catching it. of course it's odd :) 

>          < ~/.uds/rt/credentials fill RTUSER RTPASSWD RTSERVER
> What is the value of $READNULLCMD ?

less :( i feel dumb right now … removing the | fix the problem 

thanks Bart! 

-- 
Marc Chantreux (eiro on github and freenode)
http://eiro.github.com/
http://eiro.github.com/atom.xml
"Don't believe everything you read on the Internet"
    -- Abraham Lincoln


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

end of thread, other threads:[~2014-03-25 10:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-20 20:57 stdios confused by a function scope ? Marc Chantreux
2014-03-21  5:35 ` Bart Schaefer
2014-03-25 10:29   ` Marc Chantreux

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).