Score:0

How do I delete the last "enter" of the copied content?

cn flag

According to How do I pipe terminal standard output (stdout) to the clipboard, we could copy the current path via:

pwd | xclip -sel clip

However, in most cases, I want to further modify the copied path when I use it. For example, add some folders to the path before running the command:

cp (paste the path) (then, I want to add the target path)

But the pasted path have an "enter" at its end, so I don't have a chance to type my target path...

So, how could I copy the terminal standard output AND remove the last "enter" character?

Ps. I don't care how long the command is, as long as it works robustly.

muru avatar
us flag
Are you doing this in different terminals? If not, you can expand the value of `$PWD` in a command line and then edit the value.
Score:2
cn flag

Another option:

echo -n $(pwd) | xclip -sel clip
Score:2
cn flag

You can use printf to trim trailing newline:

printf %s "$PWD" | xclip -sel clip
zheyuanWang avatar
cn flag
accept printf as the answer according to https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo (No one talked about speed though)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.