Find the answer to your Linux question:
Results 1 to 6 of 6
Hi, I am using /bin/csh as default shell. From the terminal i use the command echo $SHELL and i get /bin/csh as result. Now from here i run /bin/bash, it ...
  1. #1
    Just Joined!
    Join Date
    Oct 2007
    Posts
    15

    Question getting SHELL environment

    Hi,

    I am using /bin/csh as default shell. From the terminal i use the command echo $SHELL and i get /bin/csh as result.
    Now from here i run /bin/bash, it changes the shell to bash, now when i ru echo $SHELL, i
    still get /bin/csh only, although i changed to /bin/bash.

    From where do i get the correct info? where is this chnage in shell gets updated.

    I am having a CPP code, where i need to detect the current shell, and then spawn a new similar shell.

    Please help...

  2. #2
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Smile

    Quote Originally Posted by HelloLinux View Post
    Hi,

    I am using /bin/csh as default shell. From the terminal i use the command echo $SHELL and i get /bin/csh as result.
    Now from here i run /bin/bash, it changes the shell to bash, now when i ru echo $SHELL, i
    still get /bin/csh only, although i changed to /bin/bash.

    From where do i get the correct info? where is this chnage in shell gets updated.

    I am having a CPP code, where i need to detect the current shell, and then spawn a new similar shell.

    Please help...
    I believe that's because $SHELL variable is predefined for each user. thus it's constant value.
    type
    $env
    Above command displays list of user specific values.
    You can edit this shell vairble or check out/etc/passwd file has each users default shell type.

    giis:506:506:giis:/home/giis:/bin/bash

    I'm using bash shell
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  3. #3
    Just Joined!
    Join Date
    Oct 2007
    Posts
    15
    Thanks....

    So what if from my code, i want to detect currently running shell, after i changed to say bash from csh from shell by running /bin/bash. Is there any environment variable which captures the same?

  4. #4
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Smile

    I don't think we have shell variable to grap this new shell...It's bit tricky
    Say your default shell is csh...then when you got into bash shell...now bash is the child process of csh.
    I'm not sure,I think we can achieve what u said,by using getpid() and getppid()
    and then using this process id to resolve the process name.
    First get process id of csh.
    Then get all process id which are child of csh.
    get process name of all these child process with help obtained pid.
    Check if the name matches bash or ksh or something.

    May be some one else will come up with simpler soultion.
    HTH.
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  5. #5
    Linux Engineer
    Join Date
    Nov 2004
    Location
    Ft. Polk, LA
    Posts
    796
    A thought, which I have not tested, simply running 'bash' will not invoke it as a login shell, and it might not set $SHELL because of that. Perhaps invoking it as a login shell will do so.

  6. #6
    Just Joined!
    Join Date
    Nov 2007
    Posts
    5
    I am running into this problem right now. Have you (or anyone else) found a good solution to this?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...