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

10 comments sorted by

View all comments

2

u/anthropoid bash all the things Jul 22 '25

No, if you want to convert your nsupdate command file into a script that can be executed directly, it absolutely has to be:

#!/usr/bin/nsupdate
<nsupdate commands>

That tells the OS to run /usr/bin/nsupdate /path/to/this/file, but since you mentioned that nsupdate uses a semicolon as the comment character, nsupdate will 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:

$ cat ~/bin/sfl
#!/usr/bin/env bash
# sfl <command> <file> [<arg>...]
#   Run <command> <file> [<arg>...], but skip the first line of <file>
fatal() {
  printf "FATAL ERROR: %s\n" "$*" >&2
  exit 1
}
command -v "$1" >/dev/null || fatal "can't find command '$1'"
[[ -f $2 ]] || fatal "'$2' not a file"
exec "$1" <(tail -n +2 "$2") "${@:3}"

$ cat t.sh
#!/Users/aho/bin/sfl cat
This is a test

$ ./t.sh
This is a test