英文:
Update specific text in file from shell script
问题
我正在尝试在shell脚本中从用户提示中更新文档中的特定条目。用户应该被提示输入他们的域名,然后脚本应该更新3个不同行上的'yourdomain.com'部分。文本文件的名称是.env
IMAGE_REPO=tacticalrmm/
VERSION=latest
TRMM_USER=username
TRMM_PASS=password
APP_HOST=rmm.yourdomain.com
API_HOST=api.yourdomain.com
MESH_HOST=mesh.yourdomain.com
英文:
I am trying to update specific entries in a document from a user prompt in a shell script. The user should be promoted to enter their domain name and then the script should update the 'yourdomain.com' section on 3 different lines. The name of the text file is .env
IMAGE_REPO=tacticalrmm/
VERSION=latest
TRMM_USER=username
TRMM_PASS=password
APP_HOST=rmm.yourdomain.com
API_HOST=api.yourdomain.com
MESH_HOST=mesh.yourdomain.com
答案1
得分: 0
这很容易,您可以使用sed
命令来从shell脚本中更新.env文件中的特定条目。
#!/bin/bash
read -p "Enter your domain name: " domain
sed -i "s/yourdomain.com/$domain/g" .env
echo "Updated values:"
cat .env
我这次帮助了您,但请记住,这里没有人会为任何人编写代码,我们在这里是为了解决您的代码问题并帮助您!
英文:
it is very easy, you can use sed
to update specific entries in the .env file from a shell script
#!/bin/bash
read -p "Enter your domain name: " domain
sed -i "s/yourdomain.com/$domain/g" .env
echo "Updated values:"
cat .env
I've helped you this time, but remember that no one here is writing code for anyone, we're here to solve your problems in your code and help you!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论