LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 09-27-2006, 11:59 AM   #1
Deviathan
Member
 
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, 12:05 PM   #2
Deviathan
Member
 
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, 12:29 PM   #3
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
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:
Code:
bash -c ls
 
Old 09-27-2006, 12:30 PM   #4
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 2,032

Rep: Reputation: 309Reputation: 309Reputation: 309Reputation: 309
Quote:
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.
 
  


Reply


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 LinuxQuestions.org Member Intro 1 05-12-2006 01:10 PM
Wet behind the ears Desk LinuxQuestions.org Member Intro 3 02-04-2006 03:25 PM
Ears bleeding!! Sound problems one Sw10.0 davemar Slackware 4 01-27-2005 09:14 AM
My ears exploded or my sound is not working??? Godsmackfelipe Linux - Newbie 5 02-12-2004 01:11 PM
unresolved symbols coming out my ears dave_blob Linux - Hardware 1 11-09-2003 09:10 PM


All times are GMT -5. The time now is 11:44 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration