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.
$ # example 1: with the "bc" (basic calculator) command $ <<<"k=1024; m=k*k; g=k*m; g" bc 1073741824 $ # example 2: with the "at" command $ <<< "/home/mirror/cron_rsync_mandriva_updates" at now + 1 min warning: commands will be executed using (in order) a) $SHELL b) login shell c) /bin/sh job 66 at Sat Jun 20 11:33:00 2009 $ # example 3: calculating how long it takes for a signal across the Atlantic in fibre optic cable $ # reference: https://en.wikipedia.org/wiki/Speed_of_light $ # example 3, part 1: how fast does light travel in glass? $ bc <<< "scale=4; speedoflight=186282; speedoflight/1.5" # light in glass travels at c / 1.5 124188.0000 $ # example 3, part 2: how many seconds for light to cross Atlantic in glass? $ bc <<< "scale=4; ocean=3716; speedoflight=124188; ocean/speedoflight" .0299
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.
Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?
You must be signed in to comment.
commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.
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
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:
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).