aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--src/lsh_main_func.c16
2 files changed, 12 insertions, 6 deletions
diff --git a/README.md b/README.md
index d19fbc9..0bd1473 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ Going to try and make it mostly POSIX compliant.
- [ ] all of posixsxssssss
- [ ] aliases
- [x] $vars
- - [ ] make them more than space delimited
+ - [x] make them more than space delimited
- [x] increase the SHLVL var
- [x] update pwd
- [x] quotes
diff --git a/src/lsh_main_func.c b/src/lsh_main_func.c
index aa16cbd..5f46183 100644
--- a/src/lsh_main_func.c
+++ b/src/lsh_main_func.c
@@ -67,7 +67,15 @@ char *handle_vars(char *token){
int i=0;
while (tmp_token[i]!='\0'){
if(tmp_token[i]=='$'){
- int j=0; while(tmp_token[i+j]!=' ' && tmp_token[i+j]) j++;
+ char sep[2]=" \0";
+ int j=0; while(tmp_token[i+j]){
+ j++;
+ if(tmp_token[i+j]==' ') break;
+ if(tmp_token[i+j]=='$'){
+ sep[0]='$';
+ break;
+ }
+ }
char *varname=(char*)malloce(sizeof(char)*j+1);
varname[j]='\0';
@@ -75,9 +83,7 @@ char *handle_vars(char *token){
varname[j-1]='\0';
char *env = getenv(varname);
- if(!env){
- env="";
- }
+ if(!env) env="";
free(ret_token);
int tmp_len=strlen(tmp_token);
@@ -87,7 +93,7 @@ char *handle_vars(char *token){
strcpy(ret_token,tmp_token);
strcat(ret_token,env);
- strcat(ret_token," ");
+ strcat(ret_token,sep);
if(i+j+1 < tmp_len){
strcat(ret_token,&tmp_token[i+j+1]);
}