3

Say I have my.script such as

#!/bin/bash blah blah 

and the bash interpreter accepts a --verbose argument.

How do I execute my.script passing --verbose to bash?

I know I can do bash --verbose my.script on the command line, but I need to be able to run my.script directly.

EDIT:

Ok, maybe I should have described my exact example. I'm using grunt.js build system whose cli is a script with a #! to node. Now, grunt runs plugins and one such plugin I use needs a certain flag to be enabled on node. The grunt cli script doesn't do that and I don't want to change it.

4
  • As far as this is really a build system question I think it belongs on SO. The answer you have covers the (on-topic) question in the title.CommentedJan 31, 2015 at 22:54
  • It isn't specific to the build system. I've come across this problem before where I wanted to be able to run some ruby/python scripts with some flags set on the interpreter. I know there are workarounds, but I really think I should be able to do it in the execution context.
    – beret
    CommentedJan 31, 2015 at 23:47
  • You're not going to get the answer you want here.CommentedJan 31, 2015 at 23:51
  • Or one that resolves the issue you're having, more to the point.CommentedJan 31, 2015 at 23:51

3 Answers 3

7

You can add --verbose to the shebang line:

#!/bin/bash --verbose 

If you’re running this on Linux, because of the way the kernel handles shebang lines, you can only add one parameter in this way. In shell scripts you can control certains shell options using set; in this instance

#!/bin/bash set -o verbose blah blah 

(Although that will only show commands after the set line, whereas having --verbose in the shebang line shows all the commands, including the shebang.)

4
  • Yeah, but in my case it's a third party script and I don't want to have to maintain my own version of the script
    – beret
    CommentedJan 31, 2015 at 21:13
  • 2
    @beret: That is a pretty vital aspect left out of the question as it currently stands.CommentedJan 31, 2015 at 21:19
  • 3
    @beret: if you don’t want to modify the script, you can wrap it; rename it to something else (say script.real) and create a new script which calls bash --verbose script.real. If you place both scripts in the same directory you can say base --verbose $(dirname $0)/script.real to avoid path problems.CommentedJan 31, 2015 at 22:03
  • @michael Please see my edit
    – beret
    CommentedJan 31, 2015 at 22:46
0

test.sh:

#!/bin/bash -v date : x=3 

Running it produces:

$ ./test.sh #!/bin/bash -v date Sat Jan 31 21:34:06 VET 2015 : x=3 
    0

    How about

    node --option `which grunt` 

      You must log in to answer this question.

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.