Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Using bash inline "here document" with three less-than symbols on command line

Terminal - Using bash inline "here document" with three less-than symbols on command line
<<<"k=1024; m=k*k; g=k*m; g" bc
2009-06-17 10:35:10
User: mpb
8
Using bash inline "here document" with three less-than symbols on command line

There are two ways to use "here documents" with bash to fill stdin:

The following example shows use with the "bc" command.

a) Using a delimiter at the end of data:

less-than less-than eeooff bc

> k=1024

> m=k*k

> g=k*m

> g

> eeooff

1073741824

b) using the "inline" verion with three less-than symbols:

less-than less-than less-than "k=1024; m=k*k; g=k*m; g" bc

1073741824

One nice advantage of using the triple less-than version is that the command can easily be recalled

from command line history and re-executed.

PS: in this "description", I had to use the name "less-than" to represent the less-than symbol because the commandlinefu input text box seems to eat up the real less-than symbols. Odd.

Alternatives

There are 5 alternatives - vote for the best!

Terminal - Alternatives
command <<< word
2012-02-29 03:14:54
User: adeverteuil
Functions: command
Tags: bash stdin
10

Don't do this:

echo word | command

Using a bash "here strings" and "here documents" look leeter than piping echo into the command. Also prevents subshell execution. Word is also expanded as usual.

Know a better way?

If you can do better, submit your command here.

What others think

Why not simply use echo?

echo "k=1024; m=k*k; g=k*m; g" | bc

I think it's easier to understand, and it's more portable (works with any bourne shell, not just bash and zsh).

Comment by inof 280 weeks and 2 days ago

@inof

The point is to show the use of the "

Sure, echo is an alternative but it means you have to use a pipe.

I am here on commandlinefu to learn *new* things.

Comment by mpb 280 weeks and 1 day ago

eh? that's odd: what happened to the three less-than symbols in my previous comment? Some odd character handing in the text input box for commandlinefu?

It would also be nice to be able to edit comments (eg for spelling correctione etc).

Comment by mpb 280 weeks and 1 day ago

What is the "three less-thans" operation actually called? I can't figure it out, and it's not in the TLDP guide!

Comment by chriszuma 144 weeks and 4 days ago

The "three-less-thans" operator is called a Here String in the bash man page. See also chapter 19.1 of the Advanced Bash-Scripting Guide in the TLDP.

Comment by bobnewstadt 137 weeks ago

Your point of view

You must be signed in to comment.

Related sites and podcasts