0

Below is a sed command used to replace the string $RUNTIME_DIR defined in redis.conf with an environment variable RUNTIME_DIR. But I always get an error

sed "s/\$RUNTIME_DIR/${RUNTIME_DIR}/" redis.conf
sed: 1: "s/$RUNTIME_DIR//use ...": bad flag in substitute command: 'u'

what is the correct way to use sed command with a variable as the replacement?

The content of the variable is /users/joey/dev/bigcrunch//runtime

Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523
  • Could you provide a sample line from `redis.conf` on how it is defined? – Inian Jan 03 '18 at 05:12
  • Could you also show us the content of the variable? My guess is that it contains a slash, and perhaps starts with `/usr...`. – ghoti Jan 03 '18 at 05:30
  • Darn, @tripleee ... I was going to answer this as a templating question, not a sed one! :) – ghoti Jan 03 '18 at 05:36
  • If you have another duplicate you want to link, I'll be happy to add it to the duplicate box if you don't yet have that privilege. (Oh, but you do, it seems.) – tripleee Jan 03 '18 at 05:37
  • @tripleee, I've added an old standby to the dupe list.. [This other one](https://stackoverflow.com/q/2914220/1072112) is older and almost identical question to this one, but I think it contains bad answers. Generally, I point people at https://mywiki.wooledge.org/TemplateFiles, which is about as authoritative a source as I know. I'll leave this comment for the wiki link. :) – ghoti Jan 03 '18 at 05:47
  • There's a bunch of possible canonicals and they should properly all be marked as duplicates. I simply picked my top google hit for "sed replace variable slash" so I am definitely not emotionally invested in this particular one. Maybe join the [`#!/bin/bash` chat room](https://chat.stackoverflow.com/rooms/98569/bin-bash) for brief coordination? – tripleee Jan 03 '18 at 05:53

0 Answers0