My default shell environment is bash and I would like to start a xterm with zsh and execute some commands.

In general, to execute some commands, I am using the following

xterm -e "ls -lrt;pwd;whoami"

This is executing the commands in bash shell with xterm.

To start the xterm with different shell, I am using the following.

xterm -ls /bin/zsh

So, how can I combine both of these ? When I tried. I got the below error.

[dinesh@mypc]$ xterm -ls /bin/zsh -e "ls"
xterm:  bad command line option "/bin/zsh"

How to solve this ?

  • To start xterm with zsh as the default shell, I added SHELL=/bin/zsh to my environment variables: echo "SHELL=/bin/zsh" >> /etc/environment. After that, logging out and in again should do the trick – Seraf Dec 5 '19 at 15:02

No, the -ls option to xterm doesn't take an argument, it just specifies that the shell that xterm start should be a login shell.

Here's the complete section on the -ls flag with the part which is relevant to your issue highlighted:

   -ls     This option indicates that the shell that is started in the
           xterm window will be a login shell (i.e., the first character
           of argv[0] will be a dash, indicating to the shell that it
           should read the user's .login or .profile).

           The -ls flag and the loginShell resource are ignored if -e is
           also given, because xterm does not know how to make the shell
           start the given command after whatever it does when it is a
           login shell - the user's shell of choice need not be a Bourne
           shell after all.  Also, xterm -e is supposed to provide a
           consistent functionality for other applications that need to
           start text-mode programs in a window, and if loginShell were
           not ignored, the result of ~/.profile might interfere with

           If you do want the effect of -ls and -e simultaneously, you may
           get away with something like

               xterm -e /bin/bash -l -c "my command here"

           Finally, -ls is not completely ignored, because xterm -ls -e
           does write a /var/run/wtmp entry (if configured to do so),
           whereas xterm -e does not.
  • this isn't working for me xterm -e csh -l -c 'set prompt="foo> "' – nmz787 Sep 20 '18 at 19:03
  • @nmz787 No it wouldn't. It would execute the set command and then immediately exit since the child csh shell was done. You'd be better off putting that set command in your shell's .login script. – Kusalananda Sep 20 '18 at 19:36
  • adding to the .login isn't a viable method for this, as I specifically need to do it dynamically and without editing a user's startup files... for now a friend simply recommended I start with a background color to differentiate shells xterm -bg darkred csh – nmz787 Sep 20 '18 at 21:11
  • This takes focus out of the current terminal window and take it back to XQuartz – alper Jul 15 '20 at 13:31

xterm uses the shell stored in $SHELL (variable initially set on login to your login shell) to parse the command line. So, if you want the command line to be parsed by a zsh shell, just do:

SHELL=/bin/zsh xterm -e 'echo $ZSH_VERSION; sleep 4'

Or you can just do:

xterm -e zsh -c 'echo $ZSH_VERSION; sleep 4'

When passed more than one argument, xterm won't invoke a shell to parse a command line, it will executed the first argument with its args with execvp() directly.


In addition to @Stéphane's answer, you can also set your SHELL environment variable in $HOME/.profile with export SHELL=/bin/zsh, provided that you are the only person on your system who wants to use zsh.

  • 2
    This is not advisable if the actual shell used is not zsh - as it is likely to cause problems by confusing processes or subshells spawned in the shell. At best setting this variables should be set in a localised fashion (i.e. SHELL=/bin/zsh some command) - in every other way, it's probably best to let the shell set this value by itself. – shalomb Jun 26 '17 at 12:02
  • @shalomb, no. Shells don't set $SHELL, login does. you would set $SHELL to your prefered shell (typically in ~/.profile) to override the one set by login so that applications like xterm/vi, etc execute it instead of your login shell. – Stéphane Chazelas May 17 '20 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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