minor changed

This commit is contained in:
Pin
2022-03-30 20:29:16 -04:00
parent 1d4c98b3c0
commit bc681fd5f9
2 changed files with 20 additions and 5 deletions

14
msh.c
View File

@@ -133,7 +133,15 @@ char *getPrompt() {
dup2(output.write, STDOUT_FILENO); dup2(output.write, STDOUT_FILENO);
close(STDERR_FILENO); // Do not print errors to the screen close(STDERR_FILENO); // Do not print errors to the screen
execlp("bash", "bash", "-i", "-c", "echo \"${PS1@P}\"", NULL); execlp("bash", "bash", "-i", "-c", "\
ver=$(bash --version | head -n 1 | awk \'{print $4}\' | grep -o \"...\");\
check_ver=$(echo -e \"${ver}\n4.3\" | sort -V | head -n 1);\
if [[ \"${ver}\" == \"${check_ver}\" ]]; then\
echo \"[${USER}@${pwd}]\";\
else\
echo \"${PS1@P}\";\
fi\
", NULL);
} else if (pid < 0) { // Error forking } else if (pid < 0) { // Error forking
printf("Error forking\n"); printf("Error forking\n");
} else { // Parent process } else { // Parent process
@@ -154,10 +162,6 @@ char *getPrompt() {
} while(!WIFEXITED(status) && !WIFSIGNALED(status)); } while(!WIFEXITED(status) && !WIFSIGNALED(status));
} }
if (status != 0) {
prompt = ">> ";
}
return prompt; return prompt;
} }

11
tmp.sh Normal file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
ver=$(bash --version | head -n 1 | awk '{print $4}' | grep -o ".\..")
check_ver=$(echo -e "${ver}\n4.3" | sort -V | head -n 1)
if [[ "${ver}" == "${check_ver}" ]]; then
echo "yes"
else
echo "no"
fi