Это очень походит на лейкопластырь и проблема XY , и Вы были бы более обеспеченным выяснением базовой проблемы. Однако, эти команды сделают то, в чем Вы нуждаетесь. Я записал его как функцию оболочки, не псевдоним, но просто добавляю эти строки к Вашему ~/.bashrc
файл:
fix_config(){
## Change current working directory to the directory where .config file is located
cd /path/to/config_file
## The original 17th line
old="$(sed '17q;d' .config)"
## The one you will replace it with
new="new line"
## The sed command that does the replacing
sed -i.bak "17 s/$old/$new/" .config
## Run whatever needs to be run with the modified file
command
## Copy the file back
cp .config.bak .config
## Go back to the old working directory
cd $OLDPWD
}
можно тогда выполнить его путем выполнения fix_config
.
Вот подробное решение как сценарий Python. Не буквально, что Вы просили, но решение:
#!/usr/bin/python3
import os
# change the lines below to the correct paths
path_to_configfile = "path_to_configfile" # the real one in /etc/dhcp/dhclient.conf
path_toconfigfile_a = "path_toconfigfile_a"
path_toconfigfile_b = "path_toconfigfile_b"
# change the line to the default line in the config file (leave the \n)
old_line = "old_line\n"
# change to the line number to check as an indicator
line_number = 17 # first line = 1
# change to the messages you'd like to see
config1_message = "config 1 is activated"
config2_message = "config 2 is activated"
with open(path_to_configfile) as defaultconfig:
defaultconfig = defaultconfig.readlines()
if defaultconfig[line_number-1] == old_line:
os.system('gksudo cp '+"'"+path_toconfigfile_a+"'"+" "+"'"+path_to_configfile+"'")
os.system('zenity --info --text '+'"'+config1_message+'"')
else:
os.system('gksudo cp '+"'"+path_toconfigfile_b+"'"+" "+"'"+path_to_configfile+"'")
os.system('zenity --info --text '+'"'+config2_message+'"')
Для использования его:
~/bin
папка. ~/bin
или скопируйте его в /usr/bin
для большей безопасности. После выхода из системы / входят в систему, Вы будете в состоянии переключиться между двумя версиями установки командой
toggle_config
, Вас попросят Вашего пароля, и Вы будете видеть сообщение как это:
, С другой стороны, можно создать .desktop файл с командой и заблокировать ее к средству запуска для быстрого переключения между настройками.