Friday, May 17, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 593  / 3 Years ago, mon, june 7, 2021, 9:47:00

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.


More From » command-line

 Answers
2

You can use printf to trim trailing newline:


printf %s "$PWD" | xclip -sel clip

[#1371] Wednesday, June 9, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
howesale

Total Points: 224
Total Questions: 117
Total Answers: 116

Location: Nauru
Member since Thu, May 18, 2023
1 Year ago
;