0

how would I use an answer to this script to be inputted into an sed command?

#!/usr/bin/env bash

echo "Hello, please introduce yourself."

echo -n "Your Username: "

read -r username

I need the username to be entered into a config file. how would I use the answer to “Your Username: “ to be entered into a command like sed -i ‘s/Username/Answer-to-the-question/g’ ~/Desktop/App/Config?

1 Answers1

0

sed isn't really designed to be parameterized. What you'll need to do is dynamically construct the script, though you'll have to be careful about quoting. Presumably, a user name is restricted to a subset of characters that don't require additional quoting for sed.

read -r username

sed -i "s/Username/$username/" ~/Desktop/App/Config
chepner
  • 446,329
  • 63
  • 468
  • 610