Problem setting new prompt on bash
Hey guys, it's been a while since my last post...
Anyway, I was foolin around with my slackware and wanted to make a little script to change prompts according to my mood.
Ok, here's what I did:
Is it somehow impossible what I'm trying to do?
I'll appreciate any help. Thx
You can't export a variable to the parent (shell) that you called the script from.
A different possibility would be to somehow randomize or select per day of the week which PS1 options you're going to use, and then put that in ~/.profile or ~/.bash_profile.
It's odd that your prompt doesn't change. I just copied one of your prompts into a console. As soon as I pressed <enter>, my prompt changed.
Perhaps it's a Slackware config of console behavior that you need to look into.
Try making a new file and copying his entire script in. Then call the script and see what happens.
They're right, you can't execute a program and (easily) change environment variables in the parent program. If you launch a #!/bin/bash script, it runs under its own instance of bash, not the one you started it from. So the PS1 value was good for the bash instance running the script, but once that finished and you returned to your original bash, you still had your original PS1.
Solution is to run the script under your original bash instance. Do that not by launching your script in the usual way, but by 'sourcing' it into the current shell. In other words, not by
There ya go.
Thanks to all, specially to dolsson5.
That was exactly the answer I was looking for. I hadn't realized that I was opening a new bash instance. I did as you said and it's working now.
|All times are GMT -5. The time now is 02:02 AM.|