Register
It is currently Fri Aug 01, 2014 3:49 am

To launch non-bash binaries


All times are UTC - 6 hours


Post new topic Reply to topic  [ 14 posts ] 
Author Message
 PostPosted: Tue Mar 16, 2010 6:04 pm   

Joined: Tue Mar 16, 2010 5:59 pm
Posts: 8
Hi,

As a very beginner, I've tried to write down a bash script that simply launch a non-bash binary file, say /usr/bin/mc. However this straightforward attempt
Code:
#!/bin/bash
/usr/bin/mc
exit
yields no effect at all. Could you please help me.

Thanks!


Top
 Profile  
 PostPosted: Tue Mar 16, 2010 10:33 pm   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
Well, that should work, but... what does mc do?

Anything that's executable can be executed just like that. Sometimes executables depend on a certain environment, though (such as an X server running for graphical applications).

- thobbs


Top
 Profile  
 PostPosted: Wed Mar 17, 2010 12:50 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 534
mc usually stands for Midnight Commander (a text mode file manager)
Code:
if [ -x /usr/bin/mc ]; then
   /usr/bin/mc
else
   echo "mc is not available from /usr/bin"
fi


Top
 Profile  
 PostPosted: Wed Mar 17, 2010 4:44 am   

Joined: Tue Mar 16, 2010 5:59 pm
Posts: 8
Thanks a lot,

Yours answers suggested me that the shortcomming of my script was not given by its code line /usr/bin/mc but by the fact that the whole script has been launched under an X session, not under a true shell session (meanwhile I did check and can say the script does work as expected under a true shell session). So I would restate my problem as follows. How to modify the following script
Code:
#!/bin/bash
/usr/bin/mc
exit
to the effect for it of being effective when launched under an X session?

Thanks again!


Top
 Profile  
 PostPosted: Wed Mar 17, 2010 7:35 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 534
do you want to have a link on whatever desktop you're using to "upraise" a term mc in it...

check your term manpage...

howto have a command done into a raising/popup term...


Top
 Profile  
 PostPosted: Wed Mar 17, 2010 9:43 am   

Joined: Tue Mar 16, 2010 5:59 pm
Posts: 8
No, mc is simply the well known Midnight Commander in my case and I do not intend to get any taskbar or desktop link to it but simply test the launch of a sample script (as a script beginner). Unfortunately I'm now writing from my office therefore I could not verify I certain guess on my desktop at home. After some googling, I guess the Kwrite editor (which I have used to edit the script) could be resposible for the disorder (I mean the Kwrite's implementation of the new line character). I intend to rewrite the same script by Nano (instead of Kwrite) and see what happens. Any way, several other people encountered similar problems under Windows, because of the use of Notepad in editing the script.

Grateful thanks for your help!


Top
 Profile  
 PostPosted: Wed Mar 17, 2010 11:17 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 534
please be kind, and use a real *n?x distro!

and don't ever write scripts using Windows, or you'll have to make use of tofrodos...

--
ps: not in good mood
may be worse...


Top
 Profile  
 PostPosted: Wed Mar 17, 2010 12:34 pm   

Joined: Tue Mar 16, 2010 5:59 pm
Posts: 8
Watael wrote:
please be kind, and use a real *n?x distro!

and don't ever write scripts using Windows, or you'll have to make use of tofrodos...

--
ps: not in good mood
may be worse...
Thanks!

Of course, it is quite possible for me to be wrong in my guess about Kwrite editting, but please take for granted, I only did all my exercises under a stand alone Debian 5.04 "Lenny" system (no Windows, no virtual machine, no Wine at all). I did learn about some Notepad annoying on the net and I can not simply reject the hypothesis that very-very similar issues happen in my case (there are even 100% identical error messages in my case!). I'm quite responsible about what I speak about and I do intend to get an answer in that matter.

Sincere thanks again for your kindness!


Top
 Profile  
 PostPosted: Wed Mar 17, 2010 12:47 pm   

Joined: Tue Mar 16, 2010 5:59 pm
Posts: 8
Thanks a lot, though I've only told the truth (in that I certainly did all my exercises under a Debian box) it is quite possible that your suspicion solve my problem. There is no joke here but just an amazing event in the past! I do promise to post here the final answer!

Thanks again!


Top
 Profile  
 PostPosted: Wed Mar 17, 2010 3:39 pm   

Joined: Tue Mar 16, 2010 5:59 pm
Posts: 8
Well I did check at home and my hope was not confirmed: I simply do not have an explanation why the bash script does work under a shell session but fails to work under X. Possibly an explanation will arise unexpectedly in the future.

Thanks!


Top
 Profile  
 PostPosted: Wed Mar 17, 2010 6:19 pm   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
Quote:
... (there are even 100% identical error messages in my case!) ...

What error messages?

I'm not sure I understand how you are executing the script. Are you running './myscript.sh' from a terminal, or double clicking the icon for the script file (i.e. through nautilus)? If you're going through nautilus, it should prompt you for an option to run it in a terminal; otherwise, you can change the script to run 'gnome-terminal --execute /usr/bin/mc'.

- thobbs


Top
 Profile  
 PostPosted: Thu Mar 18, 2010 3:43 am   

Joined: Tue Mar 16, 2010 5:59 pm
Posts: 8
1. Some attempts ago, the error message was
Code:
/bin/bash^M: bad interpreter: No such file or directory
Now, after several attempts and re-editting of the script, I get no message at all, but simply no effect. Rather curious is the ^M charracter combination above (in the error message) which I never typed in my scripts.

2. My attempts merely consist in double mouse clicking directly on the script icon which is located on the user Desktop (therefore, no nautilus or Dolphin etc etc but only straightforward double click on the icon). Any way, I'm working under KDE though having installed both GNOME and KDE as well.

3. By the way, some scripts do work correctly, if /usr/bin/mc is replaced by another binary. For instance, the following scripts does work under X sessions:
Code:
!#/bin/bash
nautilus
exit
However I was not able to notice clear criteria about which binary are accepted and which not. For instance, the ls command (instead of /usr/bin/mc) doesn't work (i.e. it produces no effect when trying to execute). Any way, all scripts which I tested till now do work correctly when run under true shell sessions.


Top
 Profile  
 PostPosted: Thu Mar 18, 2010 8:21 pm   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
Well, the executables do run, it's just that there's nothing hooked up to watch them -- i.e., it's not an interactive shell session. In the case of midnight commander, I suspect it checks to make sure it's in an interactive session, and if it's not, it just dies (if it didn't die, you could run 'ps' and see it). With something like ls, it could care less whether or not it's in an interactive session (try changing your script to run 'touch somefile' instead and you'll see that the file is created). With graphical programs (nautilus, for example), their purpose is not to run in a shell, but to start a graphical application, so they don't generally care if they are started in an interactive session.

There's actually quite a bit going on under the scenes. Read this if you're interested: http://www.linusakesson.net/programming/tty/index.php

- thobbs


Top
 Profile  
 PostPosted: Sat Mar 20, 2010 2:05 am   

Joined: Tue Mar 16, 2010 5:59 pm
Posts: 8
Thank you very much, I will read the materal you pointed out.
    1. I think there is a good chance that your explanation be right. For instance, I tested the same procedure (i.e. double click on the script icon) under a GNOME session and everything went OK (the MC window did pop up as expected).
    2. Furthermore, things go identically for perl instead of bash scripts (i.e. failure under KDE and success under GNOME).
    3. So could you please help me a bit more about how to fine tuning KDE in order for the user to get interactive bash sessions for scripts (as it is the case for my GNOME environment).
Thanks!


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP