Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

ksh/bash environment variable differences

Options
  • 06-11-2008 2:14pm
    #1
    Registered Users Posts: 304 ✭✭


    Hey all,

    I have a quick question. In work, I'm forever switching between korn and bourne again shells (it's apparently 'inadvisable' to have bash as your default shell at work - as you can't be sure a box you connect to will have bash, but ksh is always there) and sometimes I'll want to know which I'm in because I'll have to do it differently in one way rather than the other.

    Now, I remember hearing that there are particular environment variables that are specific to each shell (i.e. they have one that isn't in /bin/sh, and then ksh has one not in bash and so on) so you can easily tell it apart in scripts (so you don't do 'ps -fp $$'). I've been trying to search for them, but can't find them.

    Does anyone have any ideas what they are, or where I should start looking?

    Regards,
    Aoife
    Tagged:


Comments

  • Moderators, Technology & Internet Moderators Posts: 37,485 Mod ✭✭✭✭Khannie


    Could you maybe have the prompt different depending on which shell you're in? Is that what you're looking for?

    Have you come across any machines that don't have bash installed? I haven't used one since HPUX.

    Another possibility is to have binary version of bash installed in (for example) ~/bash/solaris and ~/bash/linux and have your .profile select one based on which machine you're logged into.

    Bash foreva!


  • Registered Users Posts: 868 ✭✭✭brianmc


    Hey all,

    I have a quick question. In work, I'm forever switching between korn and bourne again shells (it's apparently 'inadvisable' to have bash as your default shell at work - as you can't be sure a box you connect to will have bash, but ksh is always there) and sometimes I'll want to know which I'm in because I'll have to do it differently in one way rather than the other.

    Now, I remember hearing that there are particular environment variables that are specific to each shell (i.e. they have one that isn't in /bin/sh, and then ksh has one not in bash and so on) so you can easily tell it apart in scripts (so you don't do 'ps -fp $$'). I've been trying to search for them, but can't find them.

    Does anyone have any ideas what they are, or where I should start looking?

    Regards,
    Aoife

    If you're just talking about when working at a command line then 'echo $0' will tell you what the shell you're working with is.

    In shell scripts, ideally you would have specified the shell being used in the #! line at the top of the script?

    I'm not sure I'm getting your question though.

    Bash has a bunch of shell variables (not environment) beginning with "BASH", i.e. BASH_VERSION. I can't think of any that Ksh has that Bash doesn't off the top of my head - hmmm... PS3 isn't normally defined in Bash by default maybe.

    Edit:

    As for Bourne shell, everything that's in Bourne Shell is in Korn shell so I suppose you could check that you didn't have variables called BASH something or any variables called RANDOM or SECONDS. This doesn't sound like a smart solution to anything though.


Advertisement