I wrote this very simple script at the end of my /etc/profile:

    let key
    while [ $i -gt 0 ] ; do
        printf "\rPress 'q' to prevent starting X ($i)"
        read -rsn 1 -t 1 key # THE PROBLEM IS HERE
        if [[ $? == 0 ]] ; then

    if [[ $key != "q" ]]; then
        printf "\nStarting X..."
        exec startx

This script allows me to choose whether to start X or not when I log in. The same script works (without 'exec startx') as expected when I execute it by myself. But during profile script execution it stops on read command waiting for user input without a timeout, and after pressing any key I see the error: "not identifier: -t".

  • 2
    Are you sure you are running this code with bash and not with zsh? What is the #!-line of the script and how exactly is it being invoked? – Kusalananda Oct 27 '19 at 20:39
  • Oh, yes, I use zsh as a default shell. And I invoked the script as a bash script. But I still can't realize what's wrong with the '-t' parameter. I can't find information about differences in usage of the 'read' utility in zsh and in bash. I would appreciate it if you could explain to me what actually I do wrong. – lyu Oct 27 '19 at 22:46
  • 1
    The -n option to the read built-in utility does quite different things in bash and in zsh (causing -t to be taken as a variable to read in zsh). You seem to be running the script with zsh. What is the #!-line of the script, and exactly how do you invoke the script when it fails? – Kusalananda Oct 27 '19 at 23:08

Probably two different issues here:

  1. Your profile cannot be running anything in the profile using a shebang. Profiles have to be sourced because they export all kinds of variables for use by the login shell. If a shebang starts a different shell in a profile, then its effects would disappear when that script completes. No child process can affect the environment of its parent.
  2. At the time your profile is executed, you probably don't yet have a terminal open that can listen for a response to the read.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.