从Shell脚本中更新文件中的特定文本。

huangapple go评论69阅读模式
英文:

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!

huangapple
  • 本文由 发表于 2023年6月19日 15:17:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76504401.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定