LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-01-2013, 07:22 PM   #1
sanatan1988
LQ Newbie
 
Registered: Nov 2008
Posts: 17

Rep: Reputation: 0
/bin/sh: 0: Illegal option -h


Hi ,

I am trying to run a program in my linux machine which links to many shell scripts. Most of them have the first line as "#!/bin/sh -h". When I run the program I get the following error:
/bin/sh: 0: Illegal option -h

what kind of shell should I use ?

Last edited by sanatan1988; 04-01-2013 at 07:23 PM.
 
Old 04-01-2013, 08:03 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

I can think of three options:

1. Change your /bin/sh to link to something that understands -h
2. Change the shebang line in the scripts to something that understands -h
3. Modify the scripts to remove the -h

Evo2.

PS. "something that understands -h" is probably /bin/bash
 
Old 04-01-2013, 09:10 PM   #3
sanatan1988
LQ Newbie
 
Registered: Nov 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Hi evo2,

Thanks for your reply. Even I thought about the same, but is there a way for updating all the scripts automatically. Is there some kind of find and replace utility available? Other than that could you mind explaining your first step and how do I achieve that?

Thanks,
Sanatan
 
Old 04-01-2013, 09:15 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Try the sed tool http://www.grymoire.com/Unix/Sed.html#uh-0 ; you may need to use 'find' to find the scripts unless you already know their locations.
 
Old 04-01-2013, 10:23 PM   #5
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

Quote:
Originally Posted by sanatan1988 View Post
Even I thought about the same, but is there a way for updating all the scripts automatically. Is there some kind of find and replace utility available?
See Chris' post.

Quote:
Other than that could you mind explaining your first step and how do I achieve that?
First you should check what /bin/sh actually points to. EG: on my system:
Code:
% ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Mar  1  2012 /bin/sh -> dash*
So I can see that /bin/sh is actually /bin/dash

To change it to /bin/bash you can do something like;
Code:
cd /bin
rm sh
ln -s bash sh
this needs to be done as root.

BEWARE: this means there will be a few seconds where you do not have any /bin/sh so in priciple it is best to do this in single user mode etc... if you screw this up it can leave your system in a state without /bin/sh, which would leave your system broken.
Also be aware that some scripts on your system may actually rely on "features" of whatever /bin/sh currently points to. "dashisms" have actually been found in the wild.
YOU BEEN WARNED.

Evo2.

Sorry about the allcaps yelling, but I just want to make it very clear that you should be very careful if you choose to do this.
 
Old 04-02-2013, 12:10 AM   #6
sanatan1988
LQ Newbie
 
Registered: Nov 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Thankyou chris and Evo2 for your reply's . I managed to change the string in those script files with the following command:

Code:
find  -type f -exec sed -i 's/sh -h/sh/g' {} \;
and it works.

-Sanatan
 
Old 04-02-2013, 09:38 AM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
In case it isn't perfectly clear, /bin/sh is the system's default POSIX shell. This can be provided by quite a few different actual shell interpreters, bash, ksh, zsh, dash, ash, and probably more. But what they all have in common is that when invoked as "#!/bin/sh", the script will be interpreted according to POSIX specifications. Some shells like dash and ash are in fact very strict posix-only shells and will not understand anything outside of what's defined there.

That's why you should always explicitly set your script's shebang to that of the actual interpreter you're writing for. If you're using bash, use #!/bin/bash, and nothing else.


Finally, I recommend not using evo2's suggestion for how to change the default shell. The distribution you're using undoubtedly has other, safer ways to do so. On Debian-based systems, for example, you should use "dpkg-reconfigure <shellname>". I also recommend configure-debian, the ncurses front-end for modifying such system parameters.

http://wiki.debian.org/DashAsBinSh
https://wiki.ubuntu.com/DashAsBinSh

Check your distro's documentation for their recommended way to do it.
 
1 members found this post helpful.
Old 04-02-2013, 05:54 PM   #8
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

Quote:
Originally Posted by David the H. View Post
Finally, I recommend not using evo2's suggestion for how to change the default shell.
Indeed, it was bad form on my part to suggest manually playing with the symlinks. It is far better to use the tools that your distro provides.

Cheers,

Evo2.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] [bash] What's mean -n option? ("/bin/sh -n config.in") poplinux Linux - Software 2 06-18-2012 02:31 AM
sed: illegal option -- i say_hi_ravi Programming 7 10-10-2011 11:55 PM
/usr/bin/iconv: illegal input sequence at position catch93 Linux - Newbie 1 09-27-2011 03:40 PM
echo $PATH = /home/g3rc4n/bin:/usr/local/bin:/usr/bin:/bin:/usr/games ? i_heart_pandas Linux - Software 7 09-18-2009 08:33 AM
cross compilation error -- /usr/local/bin/ld: unrecognized option '--as-needed' shabeervsm Linux - Kernel 1 09-08-2008 04:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration