# Starting gdb with a command and its arguments

**URL:** <https://linux-tips.com/t/starting-gdb-with-a-command-and-its-arguments/784>\
**Category:** Programming\
**Created:** [March 11, 2020, 7:24am UTC](https://linux-tips.com/t/starting-gdb-with-a-command-and-its-arguments/784 "2020-03-11T07:24:05Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![DrSlump](https://linux-tips.com/user_avatar/linux-tips.com/drslump/32/61_2.png) [@DrSlump](https://linux-tips.com/u/DrSlump)\
**Post date:** [March 11, 2020, 7:24am UTC](https://linux-tips.com/t/starting-gdb-with-a-command-and-its-arguments/784/1 "2020-03-11T07:24:05Z")

</div>

In a typical gdb session, we used following steps:

```
$ gdb program
(gdb) run program-arguments

```

But, if you want to give both of the program and its arguments in one step (this is especially usefull if you have a very long argument lists and frequently switching gdb or normal start), you can use `--args` option of the **gdb** :

```
$ gdb --args program program-arguments
(gdb) 

```

As you can see, **run** command (or short hand form as **r** ) still required to start execution but at least, you don’t need to copy&paste arguments.

If you want to automatize a gdb session with gdb commands **run** , **backtrace** etc. you can write these commands in a file and start gdb with _batch_ and _x_ parameters as below:

```auto
$ gdb --batch -x commands.txt --args program program-arguments

```

---

_[View the full topic](https://linux-tips.com/t/starting-gdb-with-a-command-and-its-arguments/784)._
