0

when write command on terminal it works correctly but when write command on .sh file shows an error

my command:

echo "hell\ro" | sed -e "s/[\]r//g"

test.sh file:

#!/bin/bash
echo "hell\ro" | sed -e "s/[\]r//g"

when execute using the command bash test.sh it shows error like this sed: -e expression #1, char 10: unknown option to `s'

sed varsion sed (GNU sed) 4.7 Packaged by Debian

Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • Do you want to remove actual carriage returns or the sequence backslash, lowercase R? – Biffen Oct 25 '21 at 14:17
  • i want to remove carriage returns – Lakmuthudcl Oct 25 '21 at 14:19
  • fwiw ... *1)* OP's script works for me and does not generate any errors ... *2)* `echo "hell\ro"` generates `hell\ro` (those are the literal characters '\' and 'r' ... not a carriage return); OP may want to update the question with the output from `sed --version`, go ahead and throw in `bash --version` for good measure – markp-fuso Oct 25 '21 at 14:21
  • 1
    You need to know the difference between `sed -e "s/[\]r//g"` and `sed -e 's/[\]r//g'` Read more [HERE](https://stackoverflow.com/questions/6697753/difference-between-single-and-double-quotes-in-bash) – dawg Oct 25 '21 at 14:28

0 Answers0