Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 09-27-2006, 10:59 AM   #1
Registered: Dec 2005
Posts: 46

Rep: Reputation: 16
Commandline gurus lend me your ears

I just had someone call me up about something they perceive as a problem and I was not sure what to tell them. Anyways, it has to do with calling a shell on the commandline and passing it a command to execute, something like "sh ls" or "sh grep blah". Now oddly enough I did not know the following would happen:

[root@localhost root]# sh grep xmy
grep: /bin/grep: cannot execute binary file
[root@localhost root]# sh ls
ls: /bin/ls: cannot execute binary file

I tried this with bash instead of sh and got the same response. I tried it with tcsh and got the "tcsh: ls: No such file or directory" response. Anyone have a clue if this is appropriate behaviour?

Thanks for any responses.
Old 09-27-2006, 11:05 AM   #2
Registered: Dec 2005
Posts: 46

Original Poster
Rep: Reputation: 16
Ok so I'm thinking now that this is the right behaviour. I would presume that if you call sh from the commandline and then pass it a parameter, it's expecting that to be an interpretable script and not a binary. I tries to read the binary and gives up once it realizes that it's not in a language it understands.
Old 09-27-2006, 11:29 AM   #3
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 124Reputation: 124
If, for some reason, you want it to execute things as if they were a command passed on the command line, use bash's "-c" option:
bash -c ls
Old 09-27-2006, 11:30 AM   #4
Senior Member
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian
Posts: 2,192

Rep: Reputation: 339Reputation: 339Reputation: 339Reputation: 339
Originally Posted by Deviathan
Ok so I'm thinking now that this is the right behaviour.
That is correct. Your initial invokation with sh would be akin to asking a picture-viewer to open a music file. You're asking it to do something it doesn't know how to do, and it's explaining it's confusion to you with an error message.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Very wet behind the ears newbie mystex Member Intro 1 05-12-2006 12:10 PM
Wet behind the ears Desk Member Intro 3 02-04-2006 02:25 PM
Ears bleeding!! Sound problems one Sw10.0 davemar Slackware 4 01-27-2005 08:14 AM
My ears exploded or my sound is not working??? Godsmackfelipe Linux - Newbie 5 02-12-2004 12:11 PM
unresolved symbols coming out my ears dave_blob Linux - Hardware 1 11-09-2003 08:10 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:24 PM.

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