使用 shell 脚本编辑 .profile 或 .bash_profile

问题描述 投票:0回答:1

`我想使用 shell 脚本编辑 .profile 或 .bash_profile 的内容来更新其中的一些值。

#! /bin/sh 文件=~./配置文件 添加=“$1” 回显$添加 回声 $add >> $file

我收到第 6 行:/.profile:权限被拒绝 那么有什么办法可以做到这一点吗?

linux bash shell unix sh
1个回答
0
投票

您的文件名可能有拼写错误。试试这个:

#! /bin/sh
file=~.profile
add="$1"
echo $add
echo $add >> $file

注意,正如其他人提到的,应该使用适当的编辑器来编辑这些文件。另外,如果您使用此方法添加任何带有空格的内容,则除非您引用它,否则它只会采用第一个单词。另外,如果某些内容被破坏,以这种方式添加内容可能会弄乱您的登录。

© www.soinside.com 2019 - 2024. All rights reserved.