LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   long command line is wrapped at the beginning of the same line (https://www.linuxquestions.org/questions/linux-newbie-8/long-command-line-is-wrapped-at-the-beginning-of-the-same-line-4175441797/)

lwang3rock 12-17-2012 11:32 AM

long command line is wrapped at the beginning of the same line
 
I tried to change COLUMNS and added "export COLUMNS=250"
in my .bash_profile.
but after re-login, suppose it will pick up the updated COLUMNS variable, but it didn't. I did source the .bash_profile again, then the variable is updated. But when I use "set" command, it is still the old value. I don't know where 65 is set. and when I resize the terminal window, this value keeps changing. Can somebody explain this to me?
Thanks,
after re-login
[ipbx@lab33 ~]$ printenv COLUMNS
65
[ipbx@lab33 ~]$ echo $COUMNS

[ipbx@lab33 ~]$ echo $COLUMNS
65
[ipbx@lab33 ~]$ set|grep COLUMNS
COLUMNS=65
[ipbx@lab33 ~]$ . ~/.bash_profile
[ipbx@lab33 ~]$ echo $COLUMNS
250
[ipbx@lab33 ~]$ printenv COLUMNS
250
[ipbx@lab33 ~]$ set|grep COLUMNS
COLUMNS=65
_=COLUMNS
[ipbx@lab33 ~]$ set|grep COLUMNS
COLUMNS=65

[ipbx@lab33 ~]$ set COLUMNS=250
[ipbx@lab33 ~]$ set|grep COLUMNS
COLUMNS=94
_=COLUMNS=250
[ipbx@lab33 ~]$ set|grep COLUMNS
COLUMNS=94
[ipbx@lab33 ~]$ set|grep COLUMNS
COLUMNS=94
[ipbx@lab33 ~]$ set|grep COLUMNS
COLUMNS=126

shivaa 12-17-2012 12:03 PM

If you're using bash shell, append this variable in .bashrc or in .profile, as:
Code:

COLUMNS=250; export COLUMNS
And, also add following line at the end of your .profile:
Code:

source .bashrc
Then once logout and login to check it again, as:
Code:

echo $COLUMNS
env | grep COLUMNS
Or
printenv | grep COLUMNS


druuna 12-17-2012 12:09 PM

There's no point in setting this variable, it is (re)set by bash itself. From the man page:
Quote:

COLUMNS
Used by the select builtin command to determine the terminal
width when printing selection lists. Automatically set upon
receipt of a SIGWINCH.
Try resizing (width) your xterm (do an echo $COLUMNS before and after).

Did you try this to solve the wrapping problem or did it introduce it?

Habitual 12-17-2012 02:45 PM

Code:

shopt -s checkwinsize
in .bashrc should help. Don't forget log out|in.

lwang3rock 12-17-2012 04:45 PM

to Drunna's questions,
I was trying to solve the wrapping problem by resetting "COLUMNS". and I am using bash.
What does "shopt -s checkwinsize" do? WILL that solve the wrapping problem?

druuna 12-18-2012 12:20 AM

Quote:

Originally Posted by lwang3rock (Post 4851233)
to Drunna's questions,
I was trying to solve the wrapping problem by resetting "COLUMNS". and I am using bash.

The cause of the wrapping problem might be your prompt (PS1). Did you try to alter it?

David the H. 12-19-2012 10:31 AM

I believe there's some miscommunication at work here. I, and probably most of the others, don't understand what the "wrapping" trouble actually is, and why you think you have to mess with the COLUMNS variable to fix it.

Could you please explain exactly what your problem is, in detail?

And please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.

edit: After reading the title again a couple of times, I think druuna may be right, and you have a mis-configured prompt. If there are unprotected non-printing characters involved, you often get behavior like lines wrapping back upon themselves.

So if you've changed something in your PS1 variable, please post it (in code tags, naturally).

lwang3rock 12-27-2012 06:43 PM

Sorry about the confusion. At first, I thought that changing COLUMNS may solve the problem. But it didn't.
I didn't change PS1. Here is my PS1 value.
Code:

lwang@california:~/project/aurra$ set|grep PS1
PS1='\u@\h:\w\$ '


lwang3rock 12-27-2012 07:24 PM

for example,
Code:

19.ng@california:~/project/aurra$ scp packages/intraswitch-SP13.0.3-sp-linux.tgz lwang@192.84.
19 should be after 84., but it goes at the beginning of the line.

druuna 12-28-2012 02:31 AM

Quote:

Originally Posted by lwang3rock (Post 4858069)
for example,
Code:

19.ng@california:~/project/aurra$ scp packages/intraswitch-SP13.0.3-sp-linux.tgz lwang@192.84.
19 should be after 84., but it goes at the beginning of the line.

Did you have a look at Habitual's reply (p):

Set shopt -s checkwinsize in your /etc/bash.bashrc (or similar for your distro) to make it global or put it in ~/.bashrc to make it local.

lwang3rock 12-28-2012 12:27 PM

I tried "shopt -s checkwinsize", the wrapping didn't work immediately. After I re-size the window to smaller size, the long command was wrapped to the next line afterwards.
I looked at another shell, checkwinsize was on by default. So I am not sure if "shopt -s checkwinsize" helped.
I am going to add this shopt to my .bashrc anyway to see if I will run into the same problem again.
Thanks for help.


All times are GMT -5. The time now is 08:47 PM.