Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I set my prompt to have colors: PS1='\e[3;32m[\u#\h:\W]$ \e[m'
However, now very long commands no longer automatically cause a new line to appear. Instead, commands that go longer than one line will start appearing at the left side of the current line, overwriting the current characters.
Non-printing characters in the prompt need to be enclosed in \[...\] so that bash can accurately compute the visible length of the prompt.
PS1='\[\e[3;32m\][\u#\h:\W]$ \[\e[m\]'
^^ ^^ ^^ ^^
bash itself doesn't know that those bytes will not be displayed by the terminal; it is your terminal that, instead of displaying the 7-byte sequence \e[3;32m, simply changes the color used to display the following characters. \u, on the other hand, is replaced by the users name by bash itself, so you don't have to do anything special to tell bash how to properly handle it.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I'm running a script on terminal and it is supposed to produce a long output, but for some reason the terminal is just showing me the end of the result and I cannot scroll up to see the complete result. Is there a way to save all the terminal instructions and results until I type clear.
The script I'm using has a loop so I need to add the output of the loop if Ill be redirecting the output to a file.
Depending on your system, the size of the terminal buffer may be fixed and hence you may not be able to scroll far enough to see the full output.
A good alternative would be to output your program/script to a text file using:
user#terminal # ./nameofprogram > text_file.txt
Otherwise you will have to find a way to increase the number of lines. In some terminal applications you can go to edit>profiles>edit>scrolling tab and adjust your settings.
You can either redirect the output of your script in a file:
script > file
(Be careful to choose a file that does not exist otherwise the content will be erased)
Or you can buffer the output with less:
script | less
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
Basically I wrote a very very simple batch script to shorten the opening of Notepad++. It accepts a single argument which it passes to Notepad++. The file is named npp.bat and is located in System32 and contains the commands:
#ECHO off
Notepad++ %1
As you can see, extremely simple, but it works as intended. However this is the first case I've had where a batch file retains control of the command line. It doesn't allow any more input until Notepad++ closes.
Basically what I'm wondering is if there is a Windows equivalent of the ampersand (&) operator in Linux
put start at the end!
#ECHO off
start "X" Notepad++ %1
start launches programs (and documents, and URLs) in a separate process
the "X" paramter is not actually needed in this example. start takes the first parameter if it's a quoted string as a window title for console applications, so if your are trying to run a command with spaces in the file name has spaces it'll get quotes and start has to see find something else first or it will steal the filename.
If you do start "c:\users\yourself\documents and settings\test one.doc" start will open a cmd window with the title c:\users\yourself\documents and settings\test one.doc instead of opening the document, start "X" "c:\users\yourself\documents and settings\test one.doc" will open the document.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I'm using SSH Shell to work with a Unix system and I have a really long query in the command that I would like to edit.
However the part I need to edit is way at the beginning and the only way for me to get there is to hold down the left arrow button for about a minute (each time I need to make a new edit).
Is there a faster way to navigate?
If you are using a ahell with emacs mode command line editing commands you can use the following movement commands (Here a complete reference):
Ctrl-a Move to the start of the line.
Ctrl-e Move to the end of the line.
Alt-f Move forward a word, where a word is composed of letters and digits.
Alt-b Move backward a word.
You may be a bit faster with these.
To get emacs mode with the different shells:
bash: you have to do nothing
ksh: invoke with ksh -o emacs
tcsh: call bindkey -e
Edit: to find out the shell currently in use:
ps -p $$
Example output:
PID TTY TIME CMD
3701 pts/1 00:00:00 ksh
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 11 months ago.
Improve this question
I've written shell scripts using escape codes to move the cursor and change the color. There are however escape codes that return a response.
I'm struggling to figure out how one reads the responses to control codes that query the terminal itself, particularly within a shell script? Codes like <ESC>[6n which is "Query Cursor Position"
It doesn't seem to be standard out or standard error as far as I can tell. I am confused.
In ZSH I do the following
~ » echo "\e[6n"
~ » 3;1R
the response to the query comes through as the next Terminal command, already typed in for me. I don't understand how. I also am unclear why bash doesn't seem to demonstrate this behavior.
What do I read this value from?
The responses come through on the channel from the terminal (or terminal emulator) to the serial port (or other tty device). That's the same channel used for transmitting characters entered at the terminal keyboard; there is no out-of-band signaling.
Since you didn't read the response after sending the query, it was interpreted as a series of keypresses by your shell. The different shells have different responses to the unusual keyboard input.
To read the response properly, you have to take the terminal out of line-based ("icanon" or "cooked") mode and read a byte at a time (from the tty, i.e. possibly stdin, the same place you'd read keyboard input from) until the terminating character is found. And there's no real way to distinguish the response from any real keypresses that happened to occur at the same time.
It's an unclean business, and if you're trying to do it in a shell script you add extra pain.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
In linux, when a terminal (like xterm) gets resized to something smaller, then expanded again, its output history gets truncated to whatever the smaller width was. Does anybody know how to make the terminal remember its previous state, or wrap text so that this doesn't break?
For example, if your terminal reads something like (using | to indicate the window edge):
|user#machine$ cat file |
|file contents foobar blah blah |
|fooblah blah |
And the terminal is resized to, say 6 characters, it looks like this:
|user#m|
|file c|
|foobla|
Then putting the width back to what it was before gives:
|user#m |
|file c |
|foobla |
This can get pretty irritating when it means you lose useful console output. Does anybody have a solution?
This is one of many annoyances that led to me to write my own shell/terminal replacement gush. I use a Tk text widget for output text, which resizes sensibly and can also be switched between line-wrapping on characters or words or left-right scrolling for long lines.