Start xterm with different shell and execute commands

xtermzsh

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 ?

Best Answer

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
           that.

           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.
Related Question