From 23759e6eca3e25700ea9c944a225709e3f4231c5 Mon Sep 17 00:00:00 2001 From: nickburlett Date: Sat, 9 Dec 2006 08:04:28 +1000 Subject: [PATCH] colon-command support Shells such as bash, sh, tcsh, and ksh each support a "colon command" that causes the script to be evaluated as a bourne script. In the case of bash and sh, this command is a no-op. For others, it means the script has sh syntax. To suppor this in fish, I've added code to launch_process that checks for a ':' as the first character of p->actual_cmd. If it is a colon, the process descriptor is modified to call /bin/sh, which should exist on any POSIX system. darcs-hash:20061208220428-5830d-6bde4f1a3e8100296a60c21f9e47988e20688a77.gz --- exec.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/exec.c b/exec.c index 6a5b497db..da0c5b75a 100644 --- a/exec.c +++ b/exec.c @@ -447,7 +447,38 @@ static int setup_child_process( job_t *j, process_t *p ) static void launch_process( process_t *p ) { // debug( 1, L"exec '%ls'", p->argv[0] ); - + + /* check for a ":\n", and run system() if so */ + + FILE* f = wfopen(p->actual_cmd, "r"); + if (f != NULL) + { + char begin[1] = {0}; + fread(begin, 1, 1, f); + if (begin[0] == ':') + { + int count = 0; + int i = 1; + int j = 2; + while( p->argv[count] != 0 ) + count++; + wchar_t **res = malloc( sizeof(wchar_t*)*(count+2)); + res[0] = L"/bin/sh"; + res[1] = p->actual_cmd; + while( p->argv[i] != 0 ) + { + res[j] = p->argv[i]; + i++; + j++; + } + res[j] = NULL; + free(p->argv); + p->argv = res; + p->actual_cmd = L"/bin/sh"; + } + + } + execve ( wcs2str(p->actual_cmd), wcsv2strv( (const wchar_t **) p->argv), env_export_arr( 0 ) );