LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-21-2024, 05:19 AM   #1
linuxuser371038
Member
 
Registered: Jan 2024
Posts: 161

Rep: Reputation: 1
How do I get rid of the whitespace in this script?


I just read up that xargs should get rid of it but it doesn't have any effect.

I bought an american keyboard but in the UK so often want to use the £ sign.

Code:
echo £|xargs|xclip -selection clipboard
The result still gives a space afterwards and maybe also a carriage return too.

How to get only the pound sign?
 
Old 06-21-2024, 05:31 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,506
Blog Entries: 3

Rep: Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814
There are several ways, but one would be to use the -n option with echo. The -e option might come in handy sometime also. As usual see, "man echo", or more likely "man bash" and scroll down to the section on echo.

Last edited by Turbocapitalist; 06-21-2024 at 05:33 AM.
 
1 members found this post helpful.
Old 06-21-2024, 06:12 AM   #3
linuxuser371038
Member
 
Registered: Jan 2024
Posts: 161

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by Turbocapitalist View Post
There are several ways, but one would be to use the -n option with echo. The -e option might come in handy sometime also. As usual see, "man echo", or more likely "man bash" and scroll down to the section on echo.
Oh that is embarrassing as the answer is right there on the first page of the echo man! However I would have not thought to look at echo for the answer unless you said, even though I do quite often check man pages.
 
Old 06-21-2024, 06:19 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,702

Rep: Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535
and what is even more annoying, this "man echo" is actually wrong, you need to inspect the man page of the shell (bash) and check how this echo command was implemented inside. (echo is a builtin, but available as an external command too). It is almost the same.
 
Old 06-21-2024, 06:35 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,506
Blog Entries: 3

Rep: Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814
Kind of and kind of not. The default is probably the one built in to the shell and the default shell is Bash but the manual page for that is a monster. It takes time and effort to learn to navigate the Bash manual page.
 
Old 06-21-2024, 06:54 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,702

Rep: Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535Reputation: 7535
they are not the same, not identical, and that may lead to confusion. Suggesting an almost correct documentation is almost a good idea.
 
1 members found this post helpful.
Old 06-21-2024, 06:57 AM   #7
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,917

Rep: Reputation: 1237Reputation: 1237Reputation: 1237Reputation: 1237Reputation: 1237Reputation: 1237Reputation: 1237Reputation: 1237Reputation: 1237
Also possible here:
Code:
printf £|xclip -selection clipboard
While in general there should be a format string for the printf:
Code:
printf "%s" 'any text here' | xclip -selection clipboard
Again, there is a shell-builtin and an external /usr/bin/printf tool.

Last edited by MadeInGermany; 06-21-2024 at 06:59 AM.
 
Old 06-21-2024, 07:11 AM   #8
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,506
Blog Entries: 3

Rep: Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814
Quote:
Originally Posted by pan64 View Post
they are not the same, not identical, and that may lead to confusion. Suggesting an almost correct documentation is almost a good idea.
Yes, there are a lot of built-in commands that are have stand-alone utilities with the same name, that is enough to cause confusion on its own. time is one I've recently noticed and for certain capabilities have to invoke the external tool with a backslash or the full path.

Code:
\time -f '%E %C' somescript
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem creating BASH script with files that have whitespace scattaneo Linux - General 2 11-06-2004 05:40 PM
remove whitespace at end of file FunkyRes Programming 2 10-05-2004 12:31 AM
ignoring the "non-portable whitespace encountered at line " warning Jake13 Linux - Software 3 08-18-2004 12:34 PM
Using sed in bash to remove whitespace jimieee Programming 3 01-28-2004 10:33 AM
Font "courier" shows as whitespace. What to do? mrTK Linux - General 3 10-08-2003 02:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration