1

There are lots of great dtrace programs out there and some of them require a PID to be passed to them, in order for them to trace that PID. Inside the dtrace scripts that argument is stored in $1. Is it possible to just simply replace $1 with $target and -c on the cmdline, and rest of the script logic remains the same?

Is it just as simple as I think it should be?

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227

1 Answers1

0

You would have to populate the variable $target within your script like for example target=$1. Simply replacing it will not suffice and not work.

Lets see what we can find on documentation about this:

Positional parameters

Arguments passed to the script from the command line [1] : $0, $1, $2, $3 ...

$0 is the name of the script itself, $1 is the first argument, $2 the second, $3 the third, and so forth. [2] After $9, the arguments must be enclosed in brackets, for example, ${10}, ${11}, ${12}.

The special variables $* and $@ denote all the positional parameters.

What you can do however is something similar to this to make it more readable inside the script:

#!/bin/sh
target=$1

But that would mean nesting variables/data which is by most people coding seen as a bad practice.

Videonauth
  • 1,112
  • 11
  • 20
  • Thanks for the answer! However, my question was very specific to the D language I.e dtrace' language... I think it works differently to bash. – Junaid Shahid Nov 22 '17 at 05:29
  • No, it doesn't yet answer my question :) – Junaid Shahid Nov 22 '17 at 05:32
  • 1
    Then you maybe should [include such a script into your question](https://unix.stackexchange.com/posts/406175/edit), so people actually see what you're talking about. – Videonauth Nov 22 '17 at 05:45