Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Sed unknown option to s

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
Lavendem
Posts: 399
Joined: 2007-09-06 19:09

Sed unknown option to s

#1 Post by Lavendem »

Hello!

I am making an automated script to install a certain Windows application via Wine. Because the application itself always runs in full screen mode which results in Wine crashing it needs to be run in a Virtual Desktop.. I'm trying to achieve that by seding the .desktop file... however I can't find the problem to why this won't work:
sed -i "s/env WINEPREFIX=\"$HOME\/.wine\" wine/env WINEPREFIX=\"$HOME\/.wine\" wine explorer \/desktop=\"Wine\",800x600/ $(\/usr\/local\/bin\/fconv --init \"$HOME\/FabiusConv\/\")" "$HOME/Desktop/FabiusConv.desktop"

Thanks in advance!
NOTE: The script should be portable and that's why I need to use a double-quote instead of a singe-quote to be able to use the $HOME variable and the $(\/usr\/local\/bin\/fconv --init \"$HOME\/FabiusConv\/\") command.

Thanks in advance!

jozyba
Posts: 76
Joined: 2007-08-23 18:08

#2 Post by jozyba »

Firstly, you can avoid having to escape the forward slashes if you use a different delimiter:

Code: Select all

sed 's_/this/is/a/path_/this/is/the/replacement/path_'
Secondly, are you searching and replacing the literal string '$HOME' or its expanded form?
e.g. say that the file FabiusConv.desktop contains these two lines:

Code: Select all

env WINEPREFIX=$HOME/.wine wine
env WINEPREFIX=/home/freddy/.wine wine    # or whatever your user name is instead of 'freddy'
Then this will find and replace the first line:

Code: Select all

sed -i.bak 's_env WINEPREFIX=$HOME/.wine wine_env WINEPREFIX=$HOME/.wine wine explorer /desktop=Wine,800x600_' $HOME/Desktop/FabiusConv.desktop
And this will find and replace the second line - (just leave the $HOME variable outside the single-quotes so that the shell can expand it):

Code: Select all

sed -i.bak 's_env WINEPREFIX='$HOME'/.wine wine_env WINEPREFIX='$HOME'/.wine wine explorer /desktop=Wine,800x600_' $HOME/Desktop/FabiusConv.desktop
Thirdly, if you're not yet sure that a sed script is going to do what you want then it's a bad idea to use the edit-in-place '-i' option; even when you've perfected the script it's good to keep a backup with 'sed -i.bak ...'

Lavendem
Posts: 399
Joined: 2007-09-06 19:09

#3 Post by Lavendem »

Thanks for the lesson!

Now I learned a lot more than what I would have from the sed man page :p

jozyba
Posts: 76
Joined: 2007-08-23 18:08

#4 Post by jozyba »

Lavendem wrote:Now I learned a lot more than what I would have from the sed man page.
Yes, this is one of those situations where 'info sed' will tell you a *lot* more than 'man sed'.

Post Reply