Author Topic: TERM environment variable not set.  (Read 495 times)

Offline stuarte

  • Multiple posting newcomer
  • *
  • Posts: 16
TERM environment variable not set.
« on: August 23, 2022, 03:04:23 pm »
Hi,

I seem(?!) to be having a term problem with Code::Blocks not being able to use a terminal, except that it does use it. With a breakpoint set at line 133 (see attached file "main.txt") and running the debugger up to that point, the program displays the output shown below in a Program Console window.


warning: GDB: Failed to set controlling terminal: Operation not permitted
TERM environment variable not set.


        Word Find


         Menu
         ====
Choose level of difficulty:

Beginning <b/B>
Intermediate <i/I>
Advanced <a/A>
Quit <q/Q>
Choice: b

Find a word in:

ACDCKEYBOARDPSKQSKMOUSE

TERM environment variable not set.

Please note that the last line of the output shown above occurs after an in-program delay and might(?) somehow be triggered by the fgets() at line 133, even though this instruction has not been executed at this point. (??)

I have attached the debug log in the file "debug_log.txt". I have verified that :-
a) "Settings/Debugger.../General settings" has "Terminal to launch console programs:" is set to "xterm -T $TITLE -e"
b) my ~/.bashrc has a last line of "export TERM=xterm-256color".

With all the previous settings verified :-
a) is there some other C::B setting that must also be set ?
b) do I somehow have to "tell" GDB to also set a TERM environment variable, given that C::B is using GDB ?

Stuart

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3255
Re: TERM environment variable not set.
« Reply #1 on: August 24, 2022, 12:08:09 am »
Is it working? I think the warning "warning: GDB: Failed to set controlling terminal: Operation not permitted"  can be ignored.
What terminal are you using? Xterm?
What is your setting in Settings->Environment->Shell to run commands in ?

Offline stuarte

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: TERM environment variable not set.
« Reply #2 on: August 24, 2022, 11:25:32 am »
Good morning BlueHazzard,

Thank you for a swift reply. As I stated in my previous post, C:B is using the terminal. It's just these error messages that have me confused. You say the warning can be ignored. thank you for that. I will now do so.

"Settings/Environment.../General settings" has "Shell to run commands in:" set to "/bin/sh -c" whereas the system is using bash. As this may be the "problem" (I understand that bash is a sort of superset of sh), would it be acceptable to C::B to replace /bin/sh -c with /bin/bash -c ? That is, would C::B recognise bash as a viable shell ?

Stuart


Offline stuarte

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: TERM environment variable not set.
« Reply #3 on: August 24, 2022, 11:54:07 am »
Hi again BlueHazzard,

Errata: It would appear that the shell in use is /usr/bin/dash. It also has a "-c" option according to "man dash". Please accept my apologies for the misinformation in my previous posting.

Stuart

Offline stuarte

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: TERM environment variable not set.
« Reply #4 on: August 24, 2022, 03:22:21 pm »
Good afternoon,

Update:

I changed "Settings/Environment.../General settings/Shell to run commands in:" to /usr/bin/dash -c. This has made no difference. I am still getting the same warnings as before. Could it be that C::B does not recognise the dash shell ?

Stuart

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3255
Re: TERM environment variable not set.
« Reply #5 on: August 24, 2022, 09:08:09 pm »
I am not quite sure where this warnings are coming from, but certainly not from within codeblocks.

Also i was wrong, what i actually wanted to know is in Settings->Environment->General Settings->Terminal to launch console programs...
I would try to install xterm and select xterm in this setting and look if it gets better

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 650
Re: TERM environment variable not set.
« Reply #6 on: August 25, 2022, 03:27:42 am »
I am in agreement with BlueHazzard in the I have not seen warning coming from programs that get called from C::B being on the shell being used as all Linux and MAc shells are not created equal and work differently.

I also spotted in the last week or so that the code in different spots uses/accesses the shell in some strange ways (strange as in I do not understand why the code works one way in soma areas of the code and differently in other areas). I have not had any issues with the shell so I have not investigated it as I am working on other things.


An example of this is in compilergcc.cpp, where the first code snippet uses the config console_shell value, but the second snippet uses the environment SHELL..... I have no idea why or what ramifications this has, if any.
Code
        if (!platform::windows)
        {
            const wxString shell(Manager::Get()->GetConfigManager("app")->Read("/console_shell", DEFAULT_CONSOLE_SHELL));
            cmd->command = shell + " '" + cmd->command + "'";
        }
Code
 

        if (!platform::windows)
        {
            // for non-win platforms, use m_ConsoleTerm to run the console app
            wxString term = Manager::Get()->GetConfigManager(_T("app"))->Read(_T("/console_terminal"), DEFAULT_CONSOLE_TERM);
            term.Replace(_T("$TITLE"), titleStr);
            term.Replace(_T("$WORKDIR"), dirStr);
            cmd << term << strSPACE;

            wxString shell;
            wxGetEnv(_T("SHELL"), &shell);
            if (shell.Contains(_T("csh")))
            {
                // "The csh is a tool utterly inadequate for programming,
                //  and its use for such purposes should be strictly banned!"
                //                 -- Csh Programming Considered Harmful
                command << DEFAULT_CONSOLE_SHELL << strSPACE;
                // each shell execution must be enclosed to "":
                // xterm -T X -e /bin/sh -c "/usr/bin/cb_console_runner X"
                // here is first \"
                command << strQUOTE;
                commandIsQuoted = true;
            }
        }


Offline stuarte

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: TERM environment variable not set.
« Reply #7 on: August 25, 2022, 02:56:40 pm »
Good afternoon,

@BlueHazzard: I just checked with Synaptic and xterm version 353-1ubuntu1-20.04.2 (the latest version from the repo) is already installed. "Settings->Environment->General Settings->Terminal to launch console programs..." is set to "xterm -T $TITLE -e".

@AndrewCot: "I have not had any issues with the shell so I have not investigated it as I am working on other things." Understood. Please do not look upon my postings as some way to (somehow???) exert some kind of pressure. They are genuine requests for help. I am also mindful of a book called "The Deming Dimension" which explained, amongst many things, the need for feedback. It in both those veins that my postings are made.

Stuart