# Combine multiple commands

**URL:** <https://community.unix.com/t/combine-multiple-commands/363705>\
**Category:** Shell Programming and Scripting\
**Created:** [November 24, 2016, 3:26am UTC](https://community.unix.com/t/combine-multiple-commands/363705 "2016-11-24T03:26:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![andre666](https://community.unix.com/letter_avatar/andre666/32/5_5575768a8748004e209b776fc1b2916d.png) [@andre666](https://community.unix.com/u/andre666)\
**Post date:** [November 24, 2016, 3:26am UTC](https://community.unix.com/t/combine-multiple-commands/363705/1 "2016-11-24T03:26:31Z")

</div>

I have the following sh-script:

```nohighlight
    konsole -T todo -e vi todo.txt &
    konsole -T window1 -e ssh user@server &
    konsole -T window2 -e ssh user@server2 -e cd directory &

```

The first two lines are working fine. The first opens a txt-file, the second opens a ssh-connection.  
The third line should open a ssh-connection and then go to a dirctory, but it does not work. Can someone please tell me if it is possible to combine these two command in a script ?

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/5_5575768a8748004e209b776fc1b2916d.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [November 24, 2016, 4:12am UTC](https://community.unix.com/t/combine-multiple-commands/363705/2 "2016-11-24T04:12:47Z")

</div>

Not being familiar with `konsole` , I'd guess you could combine several commands in a "list", i.e. adding them after another separated by semicolons, eventually enclosed in (double) quotes. On top, `ssh` does allow to specify a command as a parameter. Did you consider that?

---

<div class="post-metadata">

**Author:** ![apmcd47](https://community.unix.com/letter_avatar/apmcd47/32/5_5575768a8748004e209b776fc1b2916d.png) [@apmcd47](https://community.unix.com/u/apmcd47)\
**Post date:** [November 24, 2016, 6:32am UTC](https://community.unix.com/t/combine-multiple-commands/363705/3 "2016-11-24T06:32:58Z")

</div>

Are you opening a remote session and then changing directory on that remote session? If you are you are doing it wrong as the -e option to ssh is not a "run this shell command" option.

Are you trying to keep the konsole open after the remote session closes, but change directory?

Andrew

---

<div class="post-metadata">

**Author:** ![rovf](https://community.unix.com/letter_avatar/rovf/32/5_5575768a8748004e209b776fc1b2916d.png) [@rovf](https://community.unix.com/u/rovf)\
**Post date:** [November 25, 2016, 4:03am UTC](https://community.unix.com/t/combine-multiple-commands/363705/4 "2016-11-25T04:03:12Z")

</div>

From the 'konsole' man page:

-e command

Execute command instead of the normal shell.

```
         This option will catch all following arguments passed to Konsole, and execute it as command. So this option should always be used as the last option.

```

From this, I would conclude that in your last example konsole is actually executing the command

```nohighlight
ssh user@server2 -e cd directory

```

which should cause an error message to be displayed (which you probably don't see, because the konsole window will close too quickly).

---

<div class="post-metadata">

**Author:** ![andre666](https://community.unix.com/letter_avatar/andre666/32/5_5575768a8748004e209b776fc1b2916d.png) [@andre666](https://community.unix.com/u/andre666)\
**Post date:** [November 25, 2016, 4:30am UTC](https://community.unix.com/t/combine-multiple-commands/363705/5 "2016-11-25T04:30:54Z")

</div>

@Andrew

> [@](#):
>
> Are you opening a remote session and then changing directory on that remote session? If you are you are doing it wrong as the -e option to ssh is not a "run this shell command" option.

So what is the right way then ? Can you give me a few keywords ?

> [@](#):
>
> Are you trying to keep the konsole open after the remote session closes, but change directory?

Yes, I wanna keep the konsole open and then work in it.

---

<div class="post-metadata">

**Author:** ![rbatte1](https://community.unix.com/letter_avatar/rbatte1/32/5_5575768a8748004e209b776fc1b2916d.png) [@rbatte1](https://community.unix.com/u/rbatte1)\
**Post date:** [November 25, 2016, 6:38am UTC](https://community.unix.com/t/combine-multiple-commands/363705/6 "2016-11-25T06:38:33Z")

</div>

One wonders what the point of changing directory is supposed to be. If that is all you do, then then you command will complete and the ssh will terminate putting you back to the client and you have achieved nothing except you would get an error if the directory was not accessible.

What are you really trying to do? Some context might help us understand your real purpose.

Kind regards,  
Robin

---

<div class="post-metadata">

**Author:** ![rovf](https://community.unix.com/letter_avatar/rovf/32/5_5575768a8748004e209b776fc1b2916d.png) [@rovf](https://community.unix.com/u/rovf)\
**Post date:** [November 25, 2016, 9:58am UTC](https://community.unix.com/t/combine-multiple-commands/363705/7 "2016-11-25T09:58:18Z")

</div>

@rbatte1: I guess the OP poster wants a new console window opened, which is logged into a different host AND placed in a certain directory - at least this would make sense, but we don't know for sure.

Of course there are several ways to achieve this, but unless we don't know the exact requirements, there is no point in making suggestions.
