summaryrefslogtreecommitdiff
path: root/tools/bash-c.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-22 19:13:11 -0700
committerJohn Denker <jsd@av8n.com>2012-07-29 15:32:35 -0700
commit8f18b37fd5a46d28544a4f31465c47428a43398b (patch)
tree9ac1d7a0ff916046d0748d3ac0c2ed1275f2ee4c /tools/bash-c.c
parent065d189b49449c073cfa23cba4172060abe36c6c (diff)
create the "bash-c" program, so as to make it easy to
write self-executing scripts
Diffstat (limited to 'tools/bash-c.c')
-rw-r--r--tools/bash-c.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/tools/bash-c.c b/tools/bash-c.c
new file mode 100644
index 0000000..6b2844d
--- /dev/null
+++ b/tools/bash-c.c
@@ -0,0 +1,36 @@
+//////////////
+
+using namespace std;
+#include <iostream>
+#include <string>
+#include <unistd.h>
+#include <sys/types.h>
+#include <stdio.h> /* for perror() */
+#include <stdlib.h> /* for exit() */
+
+
+string dirname(const string path){
+ size_t where = path.rfind("/");
+ if (where == string::npos) return ".";
+ return path.substr(0, where);
+}
+
+int main(int argc, char** argv){
+ int verbosity(0);
+
+ char* nargv[1+argc];
+ for (int ii = 1; ii <= argc; ii++){
+ if (verbosity) {
+ if (argv[ii] == 0) cout << "zero" << endl;
+ else cout << "[" << argv[ii] << "]" << endl;
+ }
+ nargv[1+ii] = argv[ii];
+ }
+ nargv[1] = (char*)"-c";
+ nargv[0] = (char*)"/home/jsd/bin/ECHO";
+ nargv[0] = (char*)"/bin/bash";
+
+ execv(*nargv, nargv);
+ cerr << "bash-c: exec failed for '" << *nargv << "' : ";
+ perror(0);
+}