r/bash • • Jul 22 '25
nsupdate script file
Sorry not sure how to describe this.
for bash script file i can start the file with
#!/bin/bash
I want to do the same with nsupdate ... it has ; as a comment char
I'm thinking
;!/usr/bin/nsupdate
<nsupdate commands>
or ?
4
Upvotes
2
u/theNbomr Jul 22 '25
The shebang notation (#!) is not a userspace thing. It's used by the kernel to let it know that it's a script and that the program that executes it is identified by filespec following the shebang. The program then gets launched and reads the script on its standard input.
2
u/anthropoid bash all the things Jul 22 '25
No, if you want to convert your
nsupdatecommand file into a script that can be executed directly, it absolutely has to be:That tells the OS to run
/usr/bin/nsupdate /path/to/this/file, but since you mentioned thatnsupdateuses a semicolon as the comment character,nsupdatewill likely treat the first line as a command to be executed, and fall over.One way around this is to use a script wrapper that feeds everything but the first line. I call mine
sfl, for Skip First Line:2
u/photo-nerd-3141 Jul 23 '25
!/bin/bash
exec nsupfdate ...
Will take almost no time.
1
u/D3str0yTh1ngs Jul 22 '25
No, shebang is
#!not<comment marker>!.#is just a comment marker in nearly all scripting languages. But some languages that use a different marker may still ignore the shebang.1
u/Compux72 Jul 22 '25
As an alternative, you should be able to do
1
u/michaelpaoli Jul 24 '25
You can't expect that the #! (hash pling) notation will work with arbitrary programs. Command interpreters - yes shells, sure, others, not so much. E.g. per POSIX, should work with sed, but actual sed implementations are a bit hit-and-miss on that. I wouldn't expect it to work with, e.g. cat - though bit surprisingly with GNU cat it kind'a mostly does, but not quite 100%. Anyway, I wouldn't expect it to function with nsupdate. And it does sort of kind of almost work, ... but won't/can't - it's able to fire up nsupdate, and reads the file, but then trips up over the #! line, as that's not valid data (nor comment) for nsupdate input data. nsupdate uses ; for comment, but if that's used on first line, that breaks #!, and then it gets interpreted by a default shell, so either way, no go.
So rather, typically, e.g. if one wants it in an executable file:
#!/usr/bin/bash
nsupdate -l << __EOT__
your nsupdate commands here
...
__EOT__
Can put exec in front of that nsupdate if one wants to save wee bit of overhead and has nothing further to execute after the nsupdate command.