mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-03 06:41:14 -03:00
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
This commit is contained in:
33
exec.c
33
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 ) );
|
||||
|
||||
Reference in New Issue
Block a user