You are not logged in.

#1 2013-03-01 12:09:45

Registered: 2013-02-11
Posts: 3

Different behaviour of 'read' in bash an zsh.


I want to use the following 'read-command' in a function sourced by zsh, but maybe sometimes by bash, too. It works pretty well within bash, but unfortunately it doesn't work with zsh, too.

read -i "$(sed -n "$1p" ${file})" -p "$PS1 " -e command
eval ${command}

It reads the $1'st line of a file and writes it behind the prompt. I can edit this line and finally, I can execute it with the enter button. Is there an equivalent solution for zsh?

Thanks in advance

p.s. I'm sorry for my english, it isn't my native language.


#2 2013-03-01 14:28:23

Registered: 2012-09-03
Posts: 18

Re: Different behaviour of 'read' in bash an zsh.

You will want to use something zle related to do this in zsh, as its read builtin looks to be rather separate from its line editor.

I hope that this will help you make progress with a zsh version:

if [[ -n $ZSH_VERSION ]]; then
  command=$(sed -n "$1p" ${file})
  vared -p "$PS1" command
  read -i "$(sed -n "$1p" ${file})" -p "$PS1 " -e command
eval ${command}

See also: man zshzle smile

Last edited by WesleyDimble (2013-03-01 14:28:55)


Board footer

Powered by FluxBB