I'm new to shell scripting and can't for the life of me figure out why this isn't working.
I'm trying to change the prompt from inside my shell script. It works when I type it into the terminal, but does nothing when I run the script and choose it from the menu. Here's what I have:
read input
case $input in
1) oldprompt=$PS1
export PS1="\d \t"
;;
2) echo "option 2"
;;
*) echo "option 3"
;;
esac
environment variables are local to a process and only propagate down to its children. if you execute a script and it exports variables, that, by design, has no impact on the parent process.
instead, you need to source the shell script so it executes in the current context.
# This is wrong.
$ ./myscript.sh
# This will work though.
$ . ./myscript.sh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With