Replace command in Bash script from another script
1
vote
2
answers
2645
views
I'm trying to setup a script that will fetch changes from github where a script has a command that's not executable in Mac OS X.
What I'm aiming for is to use
sed
etc to replace the command within that script.
These are the commands:
Original command (to be replaced in script):
DIR=$(dirname "$(readlink -f $0)")
New command (I want to replace with):
DIR="$(cd "$(dirname "$0")" && pwd -P)"
What I've tried so far:
StartStopScript="/path/to/script.sh"
DIRnew=""$(cd "$(dirname "$0")" && pwd -P)""
DIRold=""$(dirname "$(readlink -f $0)")""
echo "$StartStopScript" | sed -e 's/"$DIRold"/"$DIRnew"/g'
This fails and the commands seems to be executed instead of interpreted as a string.
Figure it comes down to quoting in sed
.
Grateful for any help I can get with this.
Asked by Björn Dalberg
(11 rep)
Aug 14, 2015, 10:31 AM
Last activity: May 23, 2025, 04:04 PM
Last activity: May 23, 2025, 04:04 PM