aboutsummaryrefslogtreecommitdiff
path: root/sh.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-03-08 17:44:37 +0000
committerEric Andersen <andersen@codepoet.org>2001-03-08 17:44:37 +0000
commit32f8c170b097fc89f1cbf970846ec3da1a06b20d (patch)
tree77e34758f50e08a338be3eb40b852524208d2173 /sh.c
parentca6045955d8e51b268e242f59f3b63b9fdcf90e6 (diff)
downloadbusybox-w32-32f8c170b097fc89f1cbf970846ec3da1a06b20d.tar.gz
busybox-w32-32f8c170b097fc89f1cbf970846ec3da1a06b20d.tar.bz2
busybox-w32-32f8c170b097fc89f1cbf970846ec3da1a06b20d.zip
Remember to delete un-expandable variables, and do a better job of expanding
shell-specific things in case the wordexp implementation is broken (ie. the stubbed out wordexp in uClibc). -Erik
Diffstat (limited to 'sh.c')
-rw-r--r--sh.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/sh.c b/sh.c
index 874c0aca9..65a0a25d2 100644
--- a/sh.c
+++ b/sh.c
@@ -959,15 +959,29 @@ static int expand_arguments(char *command)
959 else 959 else
960 var = itoa(last_bg_pid); 960 var = itoa(last_bg_pid);
961 break; 961 break;
962#if 0 962 /* Everything else like $$, $#, $[0-9], etc should all be
963 /* Everything else like $$, $#, $[0-9], etcshould all be 963 * expanded by wordexp(), so we can in theory skip that stuff
964 * expanded by wordexp(), so we can skip that stuff here */ 964 * here, but just to be on the safe side (i.e. since uClibc
965 * wordexp doesn't do this stuff yet), lets leave it in for
966 * now. */
965 case '$': 967 case '$':
968 var = itoa(getpid());
969 break;
966 case '#': 970 case '#':
971 var = itoa(argc-1);
972 break;
967 case '0':case '1':case '2':case '3':case '4': 973 case '0':case '1':case '2':case '3':case '4':
968 case '5':case '6':case '7':case '8':case '9': 974 case '5':case '6':case '7':case '8':case '9':
975 {
976 int index=*(dst + 1)-48;
977 if (index >= argc) {
978 var='\0';
979 } else {
980 var = argv[index];
981 }
982 }
969 break; 983 break;
970#endif 984
971 } 985 }
972 } 986 }
973 if (var) { 987 if (var) {
@@ -982,9 +996,17 @@ static int expand_arguments(char *command)
982 memmove(dst+subst_len, next_dst+1, subst_len); 996 memmove(dst+subst_len, next_dst+1, subst_len);
983 /* Now copy in the new stuff */ 997 /* Now copy in the new stuff */
984 strncpy(dst, var, subst_len); 998 strncpy(dst, var, subst_len);
999 src = dst;
1000 src++;
1001 } else {
1002 /* Seems we got an un-expandable variable. So delete it. */
1003 char *next_dst;
1004 if ((next_dst=strpbrk(dst+1, " \t~`!$^&*()=|\\{}[];\"'<>?")) != NULL) {
1005 /* Move stuff to the end of the string to accommodate filling
1006 * the created gap with the new stuff */
1007 memmove(dst, next_dst, next_dst-dst);
1008 }
985 } 1009 }
986 src = dst;
987 src++;
988 } 1010 }
989 1011
990 1012