-1

I want to make a login menu to run different profiles as per menu.

#!/usr/bin/ksh
banner welcome

echo "select the application profile:"
echo " 1) profile1"
echo " 2) profile2"

read n
case $n in
    1) . profile1;;
    2) . profile2;;
    *) invalid option;;
esac;
4
  • And your question is ... ? Aug 9, 2016 at 14:37
  • Try prepending an explicit path onto the profile files, e.g., . ./profile1;;. Aug 9, 2016 at 15:30
  • Tried ... it did not work... it stays in current profile.
    – Dev_Off
    Aug 9, 2016 at 18:40
  • How are you calling the script from your .profile? If you're not calling it with . ./script - i.e. sourcing it, the sourcing of the .profile1 or .profile2 can't take effect in the current shell. Aug 10, 2016 at 11:11

1 Answer 1

0

OK, I'm hoping I understand this correctly. Also my solution is with bash but -should- work with ksh as well

You want it so that when you run this script and select an option, it then sets that profile for the current bash session? If so you'll need to run the script slightly differently than usual.

When you run a bash script, anything that happens inside it, stays inside it so that it doesn't affect the outside session or anything else

So if you want to change the current user's profile from within a bash script, you will need to run the bash script as

source <name of script>

rather than

./<name of script>

As you might usually call it.

Try it and let me know if it works, if not I'll try to help more

3
  • # source ./profile_menu.sh ksh: source: not found. _______________ # source profile_menu.sh ksh: source: not found. Also tried .ksh did not work - Please help
    – Dev_Off
    Aug 10, 2016 at 12:49
  • OK, rather than using source - use . <script path including name> And inside the script, make sure the paths for your profile1 and profile2 are correct so the absolute path
    – vxstorm
    Aug 10, 2016 at 16:03
  • tried it didnt work - Can you please try creating in ur env ... my profile has couple of export and alias ... So pls try in ur env and let me know if you are able to do it.. thanks a lot
    – Dev_Off
    Aug 11, 2016 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.