9
0
Fork 0

process_escape_sequence: add support to \$?

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Jean-Christophe PLAGNIOL-VILLARD 2013-09-17 09:50:04 +02:00 committed by Sascha Hauer
parent 179ed619f4
commit 56ee5d3aac
4 changed files with 34 additions and 0 deletions

View File

@ -123,6 +123,7 @@
#include <linux/list.h>
#include <binfmt.h>
#include <init.h>
#include <shell.h>
/*cmd_boot.c*/
extern int do_bootd(int flag, int argc, char *argv[]); /* do_bootd */
@ -226,6 +227,11 @@ static char console_buffer[CONFIG_CBSIZE]; /* console I/O buffer */
* the first three support $?, $#, and $1 */
static unsigned int last_return_code;
int shell_get_last_return_code(void)
{
return last_return_code;
}
/* "globals" within this file */
static uchar *ifs;
static char map[256];

View File

@ -1,6 +1,15 @@
#include <common.h>
#include <command.h>
#include <environment.h>
#include <shell.h>
/*
* not yet supported
*/
int shell_get_last_return_code(void)
{
return 0;
}
static int parse_line (char *line, char *argv[])
{

12
include/shell.h Normal file
View File

@ -0,0 +1,12 @@
/*
* (C) Copyright 2013 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
*
* Under GPLv2 only
*/
#ifndef __SHELL_H__
#define __SHELL_H__
int shell_get_last_return_code(void);
#endif /* __SHELL_H__ */

View File

@ -19,6 +19,7 @@
#include <common.h>
#include <fs.h>
#include <libbb.h>
#include <shell.h>
int process_escape_sequence(const char *source, char *dest, int destlen)
{
@ -59,6 +60,12 @@ int process_escape_sequence(const char *source, char *dest, int destlen)
case 'w':
i += snprintf(dest + i, destlen - i, "%s", getcwd());
break;
case '$':
if (*(source + 2) == '?') {
i += snprintf(dest + i, destlen - i, "%d", shell_get_last_return_code());
source++;
break;
}
default:
dest[i++] = '\\';
dest[i++] = *(source + 1);