![]() You can check the termcap/terminfo database for the repeat_char/ rep capability to determine whether a terminal type supports REP. This works with pretty much all shells, even the Debian Almquist shell. So as long as your real video terminal or terminal emulator understands something that was standardized in the 1970s, and you aren't using a paper terminal (which is vanishingly unlikely), printing 20 times can be done with no shell-specific syntax, no command pipelines, no substitutions or stream editing, and just printf: printf 19 XTerm was well ahead of most and has understood it since 1996, but libVTE and KDE Konsole didn't catch up until 20. Whereas the likes of the DEC VT5xx series in the 1990s understood REP, it is only within the last decade that it has become commonplace on terminal emulators. ![]() ![]() It has taken terminal emulators some time to catch up with real terminals. This repeats the previous graphic character printed (amongst other things, which I won't go into here as we only care about graphic characters). One can take advantage of the facts that (a) video terminals are not "dumb", and never really have been and (b) nowadays, in the third decade of the 21st century, most video terminals and even their emulators, largely agree on understanding ECMA-48, rather than a control sequence system of their own.ĮCMA-48, since its earliest days in the 1970s, has defined a control sequence REP, which is CSI, a parameter, and b as the final character. There is nothing wrong in doing so, but there is an alternative approach. Other answers have taken the tack of using the extensions to standard shell syntax that are available in specific shells such as the Korn, Z, and Bourne Again shells. Print -rC1 - is like printf '%s\n' or print -rl - to print one element per line except in the case where no arguments are passed to it (like when lines=()) in which case it prints nothing instead of an empty line). Short text the m flag causes zsh to take into account the display width of each character (like for those double-width characters above (which your browser may not render with exactly double-width, but your terminal should)). If the end-goal is to display a list of strings padded to the width of the screen, you'd do: $ lines=(short 'longer text' 'even longer') ( printf '%s\n' "$string" can be written print -r - "$string" or echo -E - "$string" in zsh, though if $string doesn't contain backslashes and doesn't start with -, that can be simplified to print "$string"/ echo "$string"). You could also use print or echo here which do add a \n by default. You could also use the right padding one here). Why so?ĭo I need to further escape \n by using a backslash in sed and from within vim?.With zsh: printf '%s\n' the l left-padding parameter expansion flag. Similarly, inside the vim editor, I can not use :%s/\n/\n\n/g. (I understand that one might say that this is a matter of syntax of sed, but could one please explain the intuition behind not allowing this, so that I can get rid of my confusion. Why can't I treat "new line character" here just as I would treat any other character and run something like above command. Say, I want to insert one line space between the lines and want an output of the form:īash$sed -e 's/\n/\n\n/g' states does not work. And why this confusing 2 characters to represent end of line characters. If so, what is its ascii value? I remember that in C programs, I have checked for the read character against the value '\n'. say if I create a new file in unix(or windows), then does the file store the "end of line" information by inserting a special character in the file called as "new line character". If I have to, how would I define a "newline character". ![]() and I would like to try to spell it and see where I go wrong. This is a very basic concept, but something I have never been able to articulate that well. ![]()
0 Comments
Leave a Reply. |