summaryrefslogtreecommitdiff
path: root/tools/bash-c.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-23 02:13:11 (GMT)
committerJohn Denker <jsd@av8n.com>2012-07-23 02:36:54 (GMT)
commit5b0852f0b2ddfd7d65711daf8602492a60917fbd (patch)
treee3d0ab9107e3e01ef923a71e4cfadca40a132ea6 /tools/bash-c.c
parent010db437f35e831d170a726aad88bcc305c7b668 (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);
+}