C one-liners

/lib/ld-linux.so.2 =(echo -e '#include <stdio.h>\nint main(){printf("c one liners\\n");}' | gcc -x c -o /dev/stdout -)
/lib/ld-linux.so.2 is the runtime linker/loader for ELF binaries on Linux. =(cmd) is a zsh trick to take the output for the command "inside" it and save it to a temporary file. echo -e 'blah' | gcc -x c -o /dev/stdout - pipes the C source to gcc. -x c tells gcc that it's compiling C (which is required if it's reading from a pipe). -o /dev/stdout - tells it to write the binary to standard output and read the source from standard input. because of the the =() thing, the compiled output is stashed in a tempfile, which the loader then runs and executes, and the shell tosses the tempfile away immediately after running it.
Sample Output
c one liners

2009-02-20 06:06:29

What Others Think

use /lib/ld-linux-x86-64.so.2 for AMD64 and other 64bit OSes.
nadavkav · 614 weeks and 3 days ago
Does anyone have a bash adaption of this?
matthewbauer · 584 weeks and 6 days ago
I would think something like: echo -e "#include <stdio.h>\nint main(){printf(\"c on liners\");}" | gcc -x c -o /dev/stdout - | /lib/ld-linux.so.2 /dev/stdin would work but it doesn't.
matthewbauer · 583 weeks and 6 days ago
I did not get the output right maybe I am doing something wrong in code. I get in contact with bestessays review so they help me out and review my whole code and tell me what I am doing wrong.
Frank377 · 49 weeks and 5 days ago
I use this tool that provides me a lot of benefits. I would like to suggest this tool to my friend. he also wants to get this. nearshore software development
Elie77 · 45 weeks ago
Cafes, restaurants and other catering establishments should not hire couriers and spend resources on creating their own fleet of vehicles. The article http://light-it.net/blog/how-to-build-a-food-delivery-app-like-ubereats describes everything in detail.
Lexon · 22 weeks and 4 days ago

What do you think?

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.

What's this?

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.

Share Your Commands

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: