Issue at Hand
You wish to learn why your lines of code that are copied and pasted are truncated.
I have looked into your issue and have found that Bash typically has a line limit by default. This is most likely your issue. However, the examples you give show lines being truncated at different lengths. I will try my best to break this down.
1. Is it a terminal-related issue (Xterm in my case)?
It quite possibly is but this is due to the limitations of a default Bash environment not xterm. (Unless you have changed many defaults of xterm)
I am referencing the following posts that offer solutions to increase line length to hopefully reduce truncation. This U&L stack exchange answer covers changing window size to match what your terminal emulator expects. User saketrp offers this as a solution to making sure your window size is interpreted by your terminal correctly.
If you are using bash, you can try this.
$ shopt checkwinsize
If you don't get
Then activate it with
$ shopt -s checkwinsize
Then just attempt running another command (like ls) or resizing the window once, the above works for me every time.
For Redhat systems particularly, the issue is often caused by misconfiguring ~/.bashrc not to call /etc/bashrc. Normally, bash loads ~/.bashrc which is expected to call /etc/bashrc, which by default contains shopt -s checkwinsize.
However, this only effects interpretations of window size and not actual line length. Using the information providing in this AskUbuntu post if you have
shopt set correctly you can add the following line to your
.bashrc to increase line length.
source .bashrc to update your Bash profile.
2. the copy/paste occurs over ssh: does this generate or magnify the issue?
I would say that this is part of the issue if not part of the root cause. The workarounds you linked are solid solutions to prevent this from happening.
I suggest that if you need to copy and paste a set of commands (do you need to use them more than once?) create a Bash script of the set of commands. Then use
curl, email or whatever method to transfer files remotely you want to use.
This avoids the truncation issue entirely as outlined in the linked workarounds and you can even script the creation and/or transfer of the scripts to many servers at once.
3. Is it a bash-related issue on the server? Would it maybe not happen with another shell?
As mentioned before, yes this could be an issue with the line limits set by Bash profile settings. Other shells may not have this issue, but I am only familiar with Dash/Bash myself. However, if these are production servers or legacy systems it may not always workout as well if you begin to change environment variables. Not to say it is not impossible, however there are risks if certain packages/software/previous scripts/cronjobs rely on Bash being the default shell, changing this can have consequences.
Again, I suggest you create a script of the commands you wish to run and transfer it to the remote server to be run there to workaround this issue.
Why your commands are being truncated depends on your environment, Bash profile settings, your terminal emulator settings, and the method of copying and pasting commands. There are workarounds as you have pointed out and I suggest you use them in conjunction with scripting to avoid the issue. I am also including a link to an
xterm manpage so you can see if there are any additional settings or options you can change.
Please comment if you have any questions or issues with this answer. I appreciate feedback to correct any misconceptions and to improve my posts. I can update my answer as needed.
Best of Luck!