Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Can anyone tell me about the -t option when invoking bash?

I found the following handy command to use a lightweight terminal window as an application launcher

urxvt -geometry 80x3 -name 'bashrun' -e sh -c "/bin/bash -i -t"

Through a little investigation of its behavior i see that the -t essentially makes bash exit after executing one command, but I am curious if there is any more to that specific -t option. I cant actually find any documentation about it, and I've looked through the following docs:

I find it odd that -t is not as clearly laid out as the rest of the options

share|improve this question

3 Answers 3

You are right that it is amazingly poorly documented. What documentation that there is is quite simple:

-t      Exit after reading and executing one command.

The bash source code is available here. I looked at version 4.2. The short flags handled by bash are listed in flags.c and in there is the relevant line:

{ 't', &just_one_command },

So, -t on the command line sets the variable just_one_command. This variable is used in just one place: it occurs in an if condition at the end of a loop in eval.c:

  if (just_one_command)
    EOF_Reached = EOF;

In other words, if the -t flag is given, then, after the first command is executed, the end-of-file condition is signaled and bash exits.

MORE DETAIL

From eval.c, command line execution in bash appears to be controlled by the function reader_loop:

reader_loop ()
{
  int our_indirection_level;
  COMMAND * volatile current_command;
  USE_VAR(current_command);
  current_command = (COMMAND *)NULL;
  our_indirection_level = ++indirection_level;
  while (EOF_Reached == 0)
    {
      int code;
      code = setjmp_nosigs (top_level);

      [ ... Much code removed ... ]

      if (just_one_command)
        EOF_Reached = EOF;
    }
  indirection_level--;
  return (last_command_exit_value);
}

The loop inside reader_loop continues until it receives the signal EOF_Reached. The sole effect of the -t option is to set this flag at the end of loop which assures that the loop is executed only once.

share|improve this answer
    
Thanks all for the responses. Im marking @John1024's answer since it includes the original source code for the option. It seems I needed to look in help set for the actual documenation –  Hari Seldon Mar 16 at 18:10

It is explained in the man page, just difficult to find.

The options not mentioned in the "OPTIONS" block at the beginning are options for set which can be given as options to bash, too:

The options can also be specified as arguments to an invocation of the shell.

-t      Exit after reading and executing one command.
share|improve this answer

Using the bash builtin help, i.e. by saying help set, you'd find:

  -t  Exit after reading and executing one command.

Since bash parses a line at a time, you might have multiple commands separated by ; on the same line and those would execute. For example, the following:

set -t; echo Do something; echo do more; echo and more
echo no more

would produce

Do something
do more
and more

as the output. On the other hand, the following:

set -t
echo Do something
echo do more
echo and more
echo no more

would not produce any output.


You could look for the documentation in the info page. Say:

info bash "Shell Builtin Commands"

Navigate to * Bourne Shell Builtins:: and search for help.

share|improve this answer
    
help set seems to be what i needed. Where is it listed that help set is something to look for? I'm not being snide, i am genuinely curious. Looking through man bash again, I am not seeing any mention of it. –  Hari Seldon Mar 16 at 18:14
1  
@HariSeldon I usually refer to info pages instead of manuals for those are usually more detailed. Please refer to the edit above for finding help on help. –  devnull Mar 16 at 18:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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