PDA

View Full Version : [all variants] [SOLVED] update-menus returns "sh: Illegal option -r"



IanVonSpeedfreak
September 21st, 2008, 12:32 AM
Okay, lately I've noticed that there a number of old entries left in my menu. So I tried running "update-menus" from the command line to fix the problem. The only thing is, all I get is this recurring error message "sh: illegal option -r". So I did some searching on google and the forums for a solution/explanation. I learned that this is a problem with /bin/sh being a symlink to DASH instead of BASH, and DASH doesn't understand the -r command.

Okay, so I think I know what's going on here. As I found an explanation here (https://lists.ubuntu.com/archives/kubuntu-users/2007-October/021795.html). After doing some reading, I decided that editing the scipt for update-menus would be better than effing with the symlink for /bin/sh (and possibly effing up my system). So how would change the script for update-menus to use /bin/bash instead of /bin/sh?

marcthenarc
September 21st, 2008, 03:07 AM
I don't see the script so I'm taking an educated guess. But at the beginning of the script, do you see #!/bin/sh ? This magic line indicates Linux to call /bin/sh as the shell to run the script.

The same go with other "interpreted languages" such as perl which uses #!/bin/perl (or other paths) for perl scripts.

By replacing #!/bin/sh by #!/bin/bash, it might fix your problem.

IanVonSpeedfreak
September 21st, 2008, 03:22 AM
Thanks for your reply, I figured that out as well, but my problem is how do I go about doing so? I mean, what program do I use to edit the file? If I use a simple text editor (I used Kate), it just shows me a bunch of garbage, and warns me that if I save the binary it will create a corrupted file. I installed biew and bvi, since they're hexadecimal and binary viewers/editors, but I'm not sure how to use them to replace text.

marcthenarc
September 21st, 2008, 03:39 PM
Oh. That's a binary file. You cannot edit such file. And by the same token, it shouldn't have any of this sh problem.

The program you are trying to edit may also have a wrapper script to it: just like /usr/bin/firefox is a wrapper to /usr/lib/firefox-3.0.1/firefox with additionnal command line options. Those have #!/bin/sh headers.

IanVonSpeedfreak
September 21st, 2008, 07:54 PM
Yeah, I was a little confused, because the posts I've been reading have made it sound like I had to edit "update-menus" and not simply the shell for fvwm-crystal (although there was always note that the problem started with that program).

So, for future reference, if anyone is having this same problem, this is what I did:

I opened my text editor of choice as root (use gksu if you're using GNOME, or sudo if it's a program run inside of terminal, e.g. vi)

kdesu kate /etc/menu-methods/fvwm-crystal

the command should open a text document that looks like this:

#!/usr/bin/install-menu
#
# debian menu method for the fvwm-crystal desktop environment
# Author: Michael Stilkerich <ms@mike2k.de>
#
compat="menu-1"

!include menu.h

compat="menu-2"

outputencoding="LOCALE";

supported;
x11= "exec " $command " $@";
text= "exec FvwmCommand \'A " $command " $@\'";
endsupported;

# strip arguments from the command
function CommandWOArgs()=shell("sh -r -c 'echo -n $0' "
replace(
"\""
esc(stripdir($command), "\\$`\"")
"\"", " ", "\" \""));

# generate a file name in the fvwm-crystal appdb format.
# do nothing for sections
genmenu=ifeqelse($needs, "", "",
$basesection "/~"
replace(CommandWOArgs(), "~", "")
"~" replacewith(title(), " /", "__")
shell("/usr/share/fvwm-crystal/debian/createicon.sh \""
CommandWOArgs() "\" \"" icon() "\"")
);
startmenu="";
endmenu="";

# the root of the menu is debian
rootsection="/debian";
rootprefix="/var/lib/fvwm-crystal/Applications";

# runnable as user, but will exit with error if debian Application subdir not
# writeable (masked out by user)
userprefix=".fvwm/Applications");

treewalk="M";

# remove the whole Debian menu and rebuild from scratch
prerun="rm -rf " prefix() rootsection();

# all menu files must be executable to show up in the menu
postrun="chmod -R +x " prefix() rootsection();
# fvwm2 somehow doesn't seem to like this more than once so
# we leave him alone
#postrun="chmod -R +x " prefix() rootsection() " && killall -USR1 fvwm2";

# executed upon update-menus --remove
removemenu="rm -rf " prefix() rootsection() " && sh /usr/share/fvwm-crystal/debian/createicon.sh --remove";

# printed to the beginning of each output file
preoutput="#!/bin/sh\n# This file is autogenerated by fvwm-crystal update-menus method\n# Do not edit - any changes to this file will be lost\n";


replace every instance of "sh" with "bash", after you're done, it should look like this:


#!/usr/bin/install-menu
#
# debian menu method for the fvwm-crystal desktop environment
# Author: Michael Stilkerich <ms@mike2k.de>
#
compat="menu-1"

!include menu.h

compat="menu-2"

outputencoding="LOCALE";

supported;
x11= "exec " $command " $@";
text= "exec FvwmCommand \'A " $command " $@\'";
endsupported;

# strip arguments from the command
function CommandWOArgs()=shell("bash -r -c 'echo -n $0' "
replace(
"\""
esc(stripdir($command), "\\$`\"")
"\"", " ", "\" \""));

# generate a file name in the fvwm-crystal appdb format.
# do nothing for sections
genmenu=ifeqelse($needs, "", "",
$basesection "/~"
replace(CommandWOArgs(), "~", "")
"~" replacewith(title(), " /", "__")
shell("/usr/share/fvwm-crystal/debian/createicon.sh \""
CommandWOArgs() "\" \"" icon() "\"")
);
startmenu="";
endmenu="";

# the root of the menu is debian
rootsection="/debian";
rootprefix="/var/lib/fvwm-crystal/Applications";

# runnable as user, but will exit with error if debian Application subdir not
# writeable (masked out by user)
userprefix=".fvwm/Applications");

treewalk="M";

# remove the whole Debian menu and rebuild from scratch
prerun="rm -rf " prefix() rootsection();

# all menu files must be executable to show up in the menu
postrun="chmod -R +x " prefix() rootsection();
# fvwm2 somehow doesn't seem to like this more than once so
# we leave him alone
#postrun="chmod -R +x " prefix() rootsection() " && killall -USR1 fvwm2";

# executed upon update-menus --remove
removemenu="rm -rf " prefix() rootsection() " && bash /usr/share/fvwm-crystal/debian/createicon.sh --remove";

# printed to the beginning of each output file
preoutput="#!/bin/bash\n# This file is autogenerated by fvwm-crystal update-menus method\n# Do not edit - any changes to this file will be lost\n";


Save and close. Now open /usr/share/fvwm-crystal/debian/createicon.sh, and do the same thing (replace "sh" with "bash"). Save and close that file, and now update-menus should function normally.

I'd really like to detail this a bit more, but I think I might've already violated some forum rules with the length of this post. Thank you again, marcthenarc!

marcthenarc
September 22nd, 2008, 02:04 AM
Well, thank you. Have a pleasant Linux trip. :)