Скрипты
This commit is contained in:
parent
e0a2dd6e63
commit
7ea142c0a3
@ -1,17 +1,27 @@
|
|||||||
line_to_add=('alias hlna="hlna.py"' 'alias hlna-bot="hlna-bot.py"')
|
line1_to_add='alias hlna="hlna.py"'
|
||||||
|
line2_to_add='alias hlna-bot="hlna-bot.py"'
|
||||||
file_paths=( "/home/$SUDO_USER/.zshrc" "/home/$SUDO_USER/.bashrc" "/home/$SUDO_USER/.config/fish/config.fish" )
|
file_paths=( "/home/$SUDO_USER/.zshrc" "/home/$SUDO_USER/.bashrc" "/home/$SUDO_USER/.config/fish/config.fish" )
|
||||||
|
|
||||||
for file_path in "${file_paths[@]}"
|
for file_path in "${file_paths[@]}"
|
||||||
do
|
do
|
||||||
if [ -f "$file_path" ]; then
|
if [ -f "$file_path" ]; then
|
||||||
# Check if the line is already in the file
|
# Check if the lines are already in the file
|
||||||
grep -qF "$line_to_add" "$file_path"
|
grep -qF "$line1_to_add" "$file_path"
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "$line_to_add" >> "$file_path"
|
echo "$line1_to_add" >> "$file_path"
|
||||||
echo "Строка добавлена в $file_path"
|
echo "Alias hlna добавлен в $file_path"
|
||||||
else
|
else
|
||||||
echo "Строка уже существует в $file_path"
|
echo "Alias hlna уже есть в файле $file_path"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
grep -qF "$line2_to_add" "$file_path"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "$line2_to_add" >> "$file_path"
|
||||||
|
echo "Alias hlna-bot добавлен в $file_path"
|
||||||
|
else
|
||||||
|
echo "Alias hlna-bot уже существует $file_path"
|
||||||
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "$file_path не существует"
|
echo "$file_path не существует"
|
||||||
fi
|
fi
|
||||||
|
@ -1,16 +1,25 @@
|
|||||||
line_to_remove=('alias hlna="hlna.py"' 'alias hlna-bot="hlna-bot.py"')
|
line1_to_remove='alias hlna="hlna.py"'
|
||||||
|
line2_to_remove='alias hlna-bot="hlna-bot.py"'
|
||||||
file_paths=( "/home/$SUDO_USER/.zshrc" "/home/$SUDO_USER/.bashrc" "/home/$SUDO_USER/.config/fish/config.fish" )
|
file_paths=( "/home/$SUDO_USER/.zshrc" "/home/$SUDO_USER/.bashrc" "/home/$SUDO_USER/.config/fish/config.fish" )
|
||||||
|
|
||||||
for file_path in "${file_paths[@]}"
|
for file_path in "${file_paths[@]}"
|
||||||
do
|
do
|
||||||
if [ -f "$file_path" ]; then
|
if [ -f "$file_path" ]; then
|
||||||
# Check if the line is in the file
|
# Check if the line is in the file
|
||||||
grep -qF "$line_to_remove" "$file_path"
|
grep -qF "$line1_to_remove" "$file_path"
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
sed -i "/$line_to_remove/d" "$file_path"
|
sed -i "/$line_to_remove/d" "$file_path"
|
||||||
echo "Строка удалена из $file_path"
|
echo "Alias hlna удалён из $file_path"
|
||||||
else
|
else
|
||||||
echo "Строки нет в $file_path"
|
echo "Alias hlna нет в $file_path"
|
||||||
|
fi
|
||||||
|
|
||||||
|
grep -qF "$line2_to_remove" "$file_path"
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
sed -i "/$line_to_remove/d" "$file_path"
|
||||||
|
echo "Alias hlna-bot удалён из $file_path"
|
||||||
|
else
|
||||||
|
echo "Alias hlna-bot нет в $file_path"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "$file_path не существует"
|
echo "$file_path не существует"
|
||||||
|
Loading…
Reference in New Issue
Block a user