# Compress programs

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 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 #!/usr/bin/zsh tail -n+3$0|zcat|$@  Bash (25 24 chars not including shebang line) #!/bin/bash tail -n+3 "$0"|zcat|"$@"  • Could -n +3 be changed to -n+3? Jan 31 '11 at 23:13 • @idealmachine yes, yes it could... (tho i had to test that :D) Jan 31 '11 at 23:25 • Also just realized that if i used zsh, I would be able to lose the "s and still have it work with spaces... Jan 31 '11 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) #include<stdio.h> #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); for(o=0;++s<i;o++[b]=32)w,a[s]),o+=strlen(a[s]);w,"|zcat");q(p)b,"w"); for(;~(i=fgetc(f));fputc(i,p));fclose(p);}  ## Bash (OP solution) This is an example I came up with: cat$0 | awk 'NR > 1' | zcat | \$* ; exit

• this fails if there are spaces in any args Jan 28 '11 at 16:35
• Thanks for the info. I will leave it as such, your solution is better. Jan 28 '11 at 16:51