LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   bash shell programming (https://www.linuxquestions.org/questions/linux-general-1/bash-shell-programming-167930/)

vivek_kumbhar 04-08-2004 07:45 PM

bash shell programming
 
Hi,

i m trying to write a script that when run will invoke a new shell and change its prompt to system date:username

thanks
Vivek

oobe 04-08-2004 09:28 PM

I probably cant help but it might help if yuo show people what you have already so can give you some suggestions the more info the better

cheers

mikshaw 04-08-2004 09:54 PM

I made something similar to this for Midnight Commander because I have a multi-line prompt for regular terminals but mc only has one line of command...in other words, mc screws up the prompt..
This is what I put in .bashrc:
Code:

if [ "${mcON}" = "1" ]; then
PS1="[ \@ - \u ] "
else
set_prompt
fi

"set_prompt" is a function which sets the multiline prompt.
"mcON" is a variable which is set from an alias or command: export mcON=1; mc -b

This is not completely bug-free, though. I had to disable the mcON variable in .xinitrc in the event that I started mc in terminal before starting X.

frandalla 04-08-2004 09:55 PM

--------script starts here--------
#!/bin/bash
PS1="\d:\u" bash
--------script ends here---------

this should do, but if the PS1 variable is defined the definition on .bashrc ou .bash_profile will override this. so, you'll not be able to open another shell changing PS1's value (PS1="\d:\u" bash won't work... the profile archive will override this definition) so, instead of opening another shell you may just change actual's prompt:
export PS1="\d:\u"

vivek_kumbhar 04-12-2004 07:13 AM

Hi, the script goes like this, this script when executed will open a new shell and will have the prompt bourne$.


#!/bin/bash -x

tput clear

echo "This script will initiate a new shell and will carry the prompt \"bourne$\". "


echo "Do you wish to initiate a new shell (y/n) : "
read reply

case "$reply" in
y|Y ) ;;
n|N ) exit ;;
* ) "Invalid Argument" ; exit ;;
esac

if [ $reply != 'n|N' ] ; then
PS1="[bourne$]\$"
export PS1
sh
else
echo "Bye ! Have a good day. "


All times are GMT -5. The time now is 01:12 AM.