0

I want to write a sed script where the echoing is off, like

#!/bin/sed -n -f
s/x/u/g

but that gives my an

Invalid option -- ' '

error.

How can I do this?

U.W.
  • 1
  • 1
    Does the script have any weird/nonprinting characters (maybe a nonbreaking space)? Try printing the script with LC_ALL=C cat -vt scriptname and see if it shows anything weird. If that doesn't spot a problem, add info about your OS and version of sed. – Gordon Davisson Jan 09 '20 at 08:41
  • What do you mean by -f without a file name? – choroba Jan 09 '20 at 08:45
  • Also see https://unix.stackexchange.com/q/63979/13792 – choroba Jan 09 '20 at 08:47

1 Answers1

5

It's because you tried to pass more than one argument in the shebang. Compare:

In this particular case you can compact -n -f to -nf. In general this is not always possible. Here the script will be:

#!/bin/sed -nf
s/x/u/g

Note: It seems to me the script in its current form will print nothing because of -n. I assume you're going to expand it.