Every time Vivaldi gets updated, I have to run this sed command to apply custom.css
sudo sed -i '1s/^/@import "custom.css";/' /opt/vivaldi-snapshot/resources/vivaldi/style/common.cssNow the command works fine in the terminal but not when I try to run it by creating an alias in ~/.bash_aliases or even through a bash script (placed inside /bin/ with executable permission). I did try using full-path for "custom.css" but it still didn't work. Thanks.
Edit:
(1) Through alias:
alias vivupdate="sed -i '1s/^/@import "custom.css";/' /opt/vivaldi-snapshot/resources/vivaldi/style/common.css"When I tried to run, I'm getting this error:
$ sudo vivupdate
[sudo] password for admn:
sudo: vivupdate: command not found
$ (2) Through a Bash script:
#!/bin/bash
sed -i '1s/^/@import "custom.css";/' /opt/vivaldi-snapshot/resources/vivaldi/style/common.csscreated vivupdate.sh, made it executable and placed it inside /bin/.
Then edited sudoers file and added:
user ALL=(ALL:ALL) NOPASSWD:/bin/vivupdate.shBut when I run the script in terminal, I get this error:
sed: couldn't open temporary file /opt/vivaldi-snapshot/resources/vivaldi/style/sedCIt48u: Permission denied 3 1 Answer
Aliases aren't available to sudo. They are specific to your shell and user, and sudo is running commands as root. Therefore, if you need an alias to be run as root, you need to include the sudo in the alias definition itself. Also, you have the quoting wrong on the alias there, so it wouldn't work anyway. What you want is:
alias vivupdate="sudo sed -i '1s/^/@import \"custom.css\";/' /opt/vivaldi-snapshot/resources/vivaldi/style/common.css"Note how I escaped the inner double quotes (\"). Without that, since you are defining the alias with double quotes, the second double quote (the one before "custom.css) will signify the end.
The issue with the script is because of how sed -i behaves. Although it seems to be editing the original file, what actually happens is that it saves the edited file as a temporary copy and then renames the file back to the original. However, since you're not running it with sudo, you don't have permission to do so. The line you added to the sudoers file only means you can run sudo vivupdate.sh without a password. However, you still need to run it as sudo.
It isn't enough to add the command to sudoers, you still need to call it with sudo:
sudo /bin/vivupdate.sh 1