Write a program/script that decompresses and passes any compressed data appended at the end of the binary/file as standard input to a program specified as arguments.

$ gzip --to-stdout input >> your_solution
$ your_solution program args...

should have the same effects as:

$ program args... < input

3 Answers 3


zsh: (20 chars)

Edit: because zsh doesn't re-parse arguments like bash, I can lose the "s and it will still work with spaces in args

tail -n+3 $0|zcat|$@

Bash (25 24 chars not including shebang line)

tail -n+3 "$0"|zcat|"$@"
  • 1
    \$\begingroup\$ Could -n +3 be changed to -n+3? \$\endgroup\$ Commented Jan 31, 2011 at 23:13
  • \$\begingroup\$ @idealmachine yes, yes it could... (tho i had to test that :D) \$\endgroup\$ Commented Jan 31, 2011 at 23:25
  • \$\begingroup\$ Also just realized that if i used zsh, I would be able to lose the "s and still have it work with spaces... \$\endgroup\$ Commented Jan 31, 2011 at 23:27

C (251 chars)

Way too long to win, but I wanted to do one in a compiled language to make things interesting. (It turned out to be quite straightforward actually).

It's probably very compiler-dependent (I used GCC 4.4.3 with the default settings on 32-bit Linux)

#define q(x)FILE*x=x##open(
#define w strcpy(o+b
o,s=7462;char b[99];main(int i,char**a){q(f)*a,"r");while(--s)fgetc(f);

Bash (OP solution)

This is an example I came up with:

cat $0 | awk 'NR > 1' | zcat | $* ; exit
  • 1
    \$\begingroup\$ this fails if there are spaces in any args \$\endgroup\$ Commented Jan 28, 2011 at 16:35
  • \$\begingroup\$ Thanks for the info. I will leave it as such, your solution is better. \$\endgroup\$
    – Alexandru
    Commented Jan 28, 2011 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.