0

I have wrote the simple script

#!/bin/bash

progname=$1

sed -i.bak 's/#define SFFX "_.*"/#define SFFX "_$progname"/' path/to/file

In order to find a preprocessor directive in a C file and change it with bash. Problem is that the varibale identyfier $progname is not expanded, so that the substitution of the string #define SFFX "_foo" does not result in #define SFFX "_bar" when i run ./myscript.sh "bar".

How can one expand the varible i pass from command line into the regexp?

opisthofulax
  • 113
  • 4
  • don't use single quotes if you want expansions to happen within the quotes, see [What is the difference between the "...", '...', $'...', and $"..." quotes in the shell?](https://unix.stackexchange.com/questions/503013/what-is-the-difference-between-the-and-quotes-in-th) and [How to use a special character as a normal one in Unix shells?](https://unix.stackexchange.com/q/296141/170373) – ilkkachu Oct 02 '22 at 13:32
  • and maybe also [What characters do I need to escape when using sed in a sh script?](https://unix.stackexchange.com/q/32907/170373) – ilkkachu Oct 02 '22 at 13:33

0 Answers0