Search code examples
shellzsh

zsh shell problem specifically when I am trying to get output


read -p "Enter your name: " NAME
echo "Hello $NAME, nice to meet you".```


In terminal:

ks@USER Desktop % ./script.sh ./script.sh:read:18: -p: no coprocess Hello , nice to meet you.


[picture of the problem ][1]


  [1]: https://i.sstatic.net/ZpVri.png

Solution

  • In ZSH -p doesn't mean prompt as in Bash. See man zshbuiltins:

       read [ -rszpqAclneE ] [ -t [ num ] ] [ -k [ num ] ] [ -d delim ]
       (...)
       -p     Input is read from the coprocess.
    

    To get a prompt with ZSH implementation of read:

    $ read "?Enter your name: " NAME
    Enter your name: myname
    $ echo $NAME
    myname