diff --git a/msh.c b/msh.c index c2be6ea..b72e146 100644 --- a/msh.c +++ b/msh.c @@ -133,7 +133,15 @@ char *getPrompt() { dup2(output.write, STDOUT_FILENO); 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 printf("Error forking\n"); } else { // Parent process @@ -154,10 +162,6 @@ char *getPrompt() { } while(!WIFEXITED(status) && !WIFSIGNALED(status)); } - if (status != 0) { - prompt = ">> "; - } - return prompt; } diff --git a/tmp.sh b/tmp.sh new file mode 100644 index 0000000..268aa09 --- /dev/null +++ b/tmp.sh @@ -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