0

I use this bash script sed_no_ocr.sh which has no x property (i.e. ls -al sed_no_ocr.sh shows -rw-r--r--):

#! /bin/bash
file=$1
concatenation(){
    echo "sed -i -r -e 's/($1) ($2)/\1\2/;p' $file"
    sed -i -r -e 's/($1) ($2)/\1\2/;p' $file
}
concatenation "bypas" "sAfromALUinWB" $file

Input file E4.13.4_orig.v:

...
assign bypas sAfromALUinWB = (IDEXrs1 == MEMWBrd) && (IDEXrs1 != 0) &&
...

I use sed 4.9. But the script fails to change the input file when running . ../sed_no_ocr.sh E4.13.4_orig.v. Running sed -r -e 's/(bypas) (sAfromALUinWB)/\1\2/p' E4.13.4_orig.v in bash works.

Q: how to make above concatenation function works in the bash script?

  • In single quotes (') the variables $1... are not intrepretted – Romeo Ninov Jul 27 '23 at 05:14
  • And file is $3 – Romeo Ninov Jul 27 '23 at 05:15
  • 1
    Thanks. I didn't notice the differences between single quotes and double quotes. As man bash says "Enclosing characters in single quotes preserves the literal value of each character within the quotes", maybe I should avoid use single quotes as the default quotes. – An5Drama Jul 27 '23 at 05:46
  • This question seems also duplicate in stackoverflow which I found later. – An5Drama Jul 27 '23 at 06:02
  • Yep, the way in SO is good, maybe you can reconsider and use awk – Romeo Ninov Jul 27 '23 at 06:20
  • "maybe I should avoid use single quotes as the default quotes" - not necessarily. If you want to handle literal strings then single quotes are correct. If you want to interpolate variables ($name) and command outputs ($(date)) you should use double quotes. – Chris Davies Jul 27 '23 at 08:40
  • Thanks for above 2 comments. 1. Yes. Both awk and sed are helpful to manipulate with texts 2. Sorry for saying too absolute. I will take care when choosing whether to use single quotes or double quotes. – An5Drama Jul 27 '23 at 11:48

0 Answers0