Skip to content

Instantly share code, notes, and snippets.

@n-b
Last active April 29, 2019 03:43
Show Gist options
  • Save n-b/5162364 to your computer and use it in GitHub Desktop.
Save n-b/5162364 to your computer and use it in GitHub Desktop.
A simple self-compiling objective-c file
/*/../bin/ls > /dev/null
COMPILED=${0%.*}
clang $0 -o $COMPILED -framework Foundation;
$COMPILED; rm $COMPILED; exit;
*/
#import <Foundation/Foundation.h>
int main(int argc, char *argv[])
{
@autoreleasepool
{
NSLog(@"Hello %@",NSProcessInfo.processInfo.environment[@"USER"]);
}
return 0;
}
@trevd
Copy link

trevd commented Oct 13, 2014

@n-b Ahah I knew I couldn't have been the first to think of this :)

I used "/* 2>/dev/null " as my line 1 and doing it for a pure c file, I didn't get as far as the $0 bit :)

I definitely agree with you , It does feel dirty tricksy :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment