How to copy without replacing a .desktop, with sh?

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
ruyzz

How to copy without replacing a .desktop, with sh?

Post by ruyzz »

I have the following code:

Code: Select all

sed -i -e "s|old|New|"  /home/user/Desktop/New.desktop 
cp /home/user/Desktop/New.desktop /home/user/Desktop/example/

[code]sed -i -e "s|New|New2|"  /home/user/Desktop/New2.desktop 
cp /home/user/Desktop/New2.desktop /home/user/Desktop/example/

Although I change the name and re-copy it, it is replaced.

How do I copy .desktop files without replacing them?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
MrEen
Level 23
Level 23
Posts: 18343
Joined: Mon Jun 12, 2017 8:39 pm

Re: How to copy without replacing a .desktop, with sh?

Post by MrEen »

Hi ruyzz.

Just use:

Code: Select all

cp /path/to/oldfile.desktop /path/to/newfile.desktop
ganamant
Level 4
Level 4
Posts: 384
Joined: Sun Mar 29, 2015 4:08 pm

Re: How to copy without replacing a .desktop, with sh?

Post by ganamant »

What are you attempting with sed? Your command will replace the first instance of the string "old" with the string "New" within the file, not in the filename. You can do as MrEen has suggested, or you can do

Code: Select all

</path/to/oldfile.desktop cat >path/to/newfile
If you actually need to do stream editing, use sed with the proper expression instead of cat.

Take a look at

Code: Select all

sed --help
man sed
info sed
in order of verbosity.
Locked

Return to “Scripts & Bash”