0

my command is

sh abc.sh 'hello'
  

Inside my shell script abc.sh

var1=$1
sed -i "s/'/ /g" $var1 

but sed is not working

anubhava
  • 761,203
  • 64
  • 569
  • 643

2 Answers2

0

sed wait filename in argument (see man sed)

sed [OPTION] .... {script-only-if-no-other-script} [input-file]

Into your script, you need to change to:

echo "$var1" | sed "s/'/ /g"
apapillon
  • 116
  • 7
  • 1
    You also need to [quote the variable](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable). – tripleee Feb 12 '21 at 12:55
0

You are performing sed on a variable and not a file and so redirect the variable back into sed to get the desired result:

sed "s/'//g" <<< "$var1"

This avoids the inefficiencies associated with echo "$var1" | sed .....

An alternative to sed in this use case is tr and so:

tr -d "'" <<< "$var1"

Use -d "'" to pass the character you want to delete from the text.

Raman Sailopal
  • 12,320
  • 2
  • 11
  • 18