On Fri, Nov 25, 2011 at 10:27:07PM -0500, Chet Ramey wrote: > >On 11/24/11 11:48 AM, QGZ wrote: > >> Bash Version: 4.1 >> Patch Level: 5 >> Release Status: release >> >> >> >> Description: >> When I use "tput lines" to get the lines of console, it works, and >> also works in a script. >> And if execute the command in a script with the command >> substitution, it works well too. >> But if execute the script with the redirection "2>/dev/null", it >> won't work well. >> I'm not sure whether it is a bug or just my lack of some required >> knowledge. >> Please see one example below. > >This doesn't have anything to do with bash. tput probably uses the >standard output as a handle to the terminal. When run in a command >substitution, stdout is a pipe. You might take a look at what tput >does using a system call tracer like truss or strace. > >Chet >
Thanks for your suggestion! I have got what happened there with the help which is similar to yours from Jonathan Nieder <jrnie...@gmail.com>: "Tput checks if the standard output (file descriptor 1) and standard error (file descriptor 2) streams are terminals and communicates with the terminal using whichever one is a tty." It's working now when executing in a command substitution in a script like this: echo $(tput lines 2>/dev/tty) Thank you! --QGZ