Mary
Mary

Reputation: 1125

How can I capture the raw command that a shell script is running?

As an example, I am trying to capture the raw commands that are output by the following script:

https://github.com/adampointer/go-deribit/blob/master/scripts/generate-models.sh

I have tried to following a previous answer:

BASH: echoing the last command run

but the output I am getting is as follows:

last command is gojson -forcefloats -name="${struct}" -tags=json,mapstructure -pkg=${p} >> models/${p}/${name%.*}_request.go

What I would like to do is capture the raw command, in other words have variables such as ${struct}, ${p} and ${p}/${name%.*} replaced by the actual values that were used.

How do I do this?

Upvotes: 2

Views: 982

Answers (2)

0.sh
0.sh

Reputation: 2762

At the top of the script after the hashbang #!/usr/bin/env bash or #!/bin/bash (if there is any) add set -x

set -x Print commands and their arguments as they are executed

Upvotes: 2

Ian McGowan
Ian McGowan

Reputation: 3801

Run the script in debug mode which will trace all the commands in the script: https://stackoverflow.com/a/10107170/988525.

You can do that without editing the script by typing "bash generate-models.sh -x".

Upvotes: 0

Related Questions