I have a file sedstr.sh containing a function sedstr:
#!/bin/bash
function sedstr {
# From stackoverflow.com/a/29626460/633251 (Thanks Ed!)
old="$1"
new="$2"
file="${3:--}"
escOld=$(sed 's/[^^]/[&]/g; s/\^/\\^/g' <<< "$old")
escNew=$(sed 's/[&/\]/\\&/g' <<< "$new")
sed -i.tmp "s/\<$escOld\>/$escNew/g" "$file" # added -i.tmp
echo "sedstr done"
}
I have an external file "test" to be edited in place with these contents:
My last name is Han.son and I need help.
If the makefile works, I'll have a new last name.
I want to call the sedstr function with its arguments from a makefile. Nothing should be returned, but the external file should be edited. Here is a small makefile that doesn't work:
all: doEdit
doEdit:
$(shell ./sedstr.sh) # I was hoping this would bring the function into the scope, but nay
$(shell sedstr 'Han.son', 'Dufus', test)
How can I call this function using variables in the makefile? The error is:
make: sedstr: Command not found
make: Nothing to be done for `all'.