-1
#! /bin/bash
A=$1
B=$2

i= ... # i is a filename generated with find command
j="$(echo $i | sed -E 's/$A/$B/')"

I am trying to change part of i, (A in this case), into something else (B in this case), and store it in j.

I've executed this, but apparently j is identical to i. I'm pretty sure I've put command line arguments correctly.

Did I do something wrong?

Benjamin W.
  • 33,075
  • 16
  • 78
  • 86
Haxify
  • 319
  • 2
  • 7
  • 16
  • 2
    You need to use double quotes for your `sed` command for the shell to expand the variables i.e. `sed -E "s/$A/$B/"` – Pankrates Jan 26 '16 at 00:39
  • Check if `j="${i/$A/$B}"` is OK too. From your example it seems like `sed` is not necessary - but can't be 100% sure. – Rany Albeg Wein Jan 26 '16 at 01:03

1 Answers1

0

You need to replace single quotes with double quotes in 's/$A/$B/'. The following command should work.

j=$( echo $i | sed -E "s/$A/$B/" )
Benjamin W.
  • 33,075
  • 16
  • 78
  • 86
Liang Liu
  • 21
  • 5