Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Copyright © 2022 Benoît Boudaud <https://miamondo.org/contact/>
- # This program is free software: you can redistribute it and/or modify it
- # under the terms of the GNU General Public License as published by the
- # Free Software Foundation, either version 3 of the License, or any later version. This
- # program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- # See the GNU General Public License for more details. You should have received a copy of the GNU
- # General Public License along with this program. If not, see <http://www.gnu.org/licenses/>
- # This code replaces a string by using the sed command. In the example below, I browse all launcher
- # files in the /usr/share/applications directory looking for the string "Exec=firefox http"
- # which I replace with "Exec=vivaldi-stable http."
- directory=/usr/share/applications
- for app in `ls "$directory"`
- do
- if ! [[ -d "$app" ]]
- then
- sed -i 's/Exec=firefox http/Exec=vivaldi-stable http/g' $directory/$app
- fi
- done
- # -------------------------------------------------------------------------------------------------
- # it is possible to pass three parameters to the script (Directory, replaced text, new text) So the
- # command would be:
- # sed_substitute.sh /usr/share/applications Exec=firefox http Exec=vivaldi-stable http
- # And the code should be:
- # for app in `ls $1`
- # do
- # if ! [[ -d "$app" ]]
- # then
- # sed -i "s/$2/$3/g" $1/$app
- # fi
- # done
- # line 39 : Take care of double quoting the sed expression. You have to do so, if this one contains
- # variables. Otherwise, it doesn't work.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement