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

#!/bin/sed -n -f

but that gives my an

Invalid option -- ' '


How can I do this?

  • 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. Jan 9, 2020 at 8:41
  • What do you mean by -f without a file name?
    – choroba
    Jan 9, 2020 at 8:45
  • Also see unix.stackexchange.com/q/63979/13792
    – choroba
    Jan 9, 2020 at 8:47

1 Answer 1


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

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.

  • 2
    Note also that -fn would most likely not work.
    – Kusalananda
    Jan 9, 2020 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.