• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Continued problems with bash scripts on Ubuntu

 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a .sh file that I would like to open/execute when I click on it in the Nemo file explorer.  I get an error when I open the folder with the file, select the file,right-click, select Open and Run in Terminal:
I get the following message in a new window:


There was an error creating child process for this terminal
Failed to execute child process: " ... path to .sh file":  Failed to execve: No such file or directory


Note text was execve

If I open a terminal in the folder with the .sh file and enter: bash ...sh   the file executes:


normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ bash Install_CdTimer.sh
* daemon not running; starting now at tcp:5037
* daemon started successfully
error: no devices/emulators found
Performing Push Install
adb: error: failed to get feature set: no devices/emulators found
Press Enter
normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$



I am trying to use the adb command to install an apk file in a android virtual machine running in VirtualBox

What do I need to do to make a script that will execute from a folder?

The .sh file:


#! /bin/sh
# set -xtrace
# @rem  Install some APKs
# /home/normt/Work/AndroidDevelopment/adt-bundle-linux-x86_64-20140702/sdk/platform-tools/adb devices
/home/normt/Work/AndroidDevelopment/adt-bundle-linux-x86_64-20140702/sdk/platform-tools/adb install ./Apks/CountdownTimer.apk
read -p "Press Enter"

 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you set the "x" bit on the shell script's access rights?
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is that set in the Permissions page - Allow to execute?
 
Greenhorn
Posts: 23
MySQL Database PHP Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:Is that set in the Permissions page - Allow to execute?


Yes
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is set.  What else needs to be checked or changed to get the .sh file to execute?
 
J Bosch
Greenhorn
Posts: 23
MySQL Database PHP Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at this thread: https://coderanch.com/t/770009/languages/bash-script-execute

Which desktop manager are you using?
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought that other thread was for script files that were on the desktop.  The ones I am trying to get to work are not on the desktop.

I have the default desktop manager:  GNOME
 
J Bosch
Greenhorn
Posts: 23
MySQL Database PHP Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does it work with any other scripts?

I am wondering if Nemo hasn't been setup with how to "Open in Terminal"

https://winaero.com/how-to-set-the-default-terminal-app-in-nemo/
 
J Bosch
Greenhorn
Posts: 23
MySQL Database PHP Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it is setup, what is the default Terminal set to?
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have not found any scripts that work.  Although the only ones that I have seen are the ones that I have tried to write.

what is the default Terminal set to?


How do I tell?  I have not changed anything about Ubuntu after the install other than adding a second file explorer: Nemo
I thought Nemo worked better than Nautilus.  
 
J Bosch
Greenhorn
Posts: 23
MySQL Database PHP Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you see when you go through the steps on the page? https://winaero.com/how-to-set-the-default-terminal-app-in-nemo/

Don't know if it matters but what version of Ubuntu?
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get Command not found when I enter cinnamon-settings in the box from Alt-F2
I think the version is 22.04

Do you have any script files that run in bash and that can be executed by clicking on them in a file explorer like nautilus?
 
J Bosch
Greenhorn
Posts: 23
MySQL Database PHP Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it works here, I am running lubuntu with PCmanFM-QT

Try this article: https://itsfoss.com/change-default-terminal-ubuntu/

 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have any script files that run in bash and that can be executed by clicking on them in a file explorer like nautilus?

Why would I want to change the terminal?

Should I expect bash scripts to work on my system?  Or are they normally turned off somehow and I need to fiddle some settings to get them to work?
 
J Bosch
Greenhorn
Posts: 23
MySQL Database PHP Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:Do you have any script files that run in bash and that can be executed by clicking on them in a file explorer like nautilus?


Yes

Norm Radder wrote:Why would I want to change the terminal?


I am wanting to see if the default terminal is setup.

Norm Radder wrote:Should I expect bash scripts to work on my system?  Or are they normally turned off somehow and I need to fiddle some settings to get them to work?


You can run the scripts in your terminal, as I see it the problem is "Open and Run in Terminal" execution in Nemo. Which is why I am wanting to check the default terminal setting.
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

normt@norm-HP-EliteDesk-800-G2-DM-35W:~$ sudo update-alternatives --config x-terminal-emulator
[sudo] password for normt:
There is only one alternative in link group x-terminal-emulator (providing /usr/bin/x-terminal-emulator): /usr/bin/gnome-terminal.wrapper
Nothing to configure.
normt@norm-HP-EliteDesk-800-G2-DM-35W:~$



I can not run the script in a terminal either.

normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ ./KillStart_Server.sh
bash: ./KillStart_Server.sh: /usr/bin/bash^M: bad interpreter: No such file or directory
normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ ./KillStart_Server.sh
bash: ./KillStart_Server.sh: /usr/bin/bash^M: bad interpreter: No such file or directory


normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ bash KillStart_Server.sh
: invalid option.sh: line 5: set: -
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
adb: unknown command devices
adb: unknown command kill-server
adb: unknown command start-server
Press ENter


>>>>>>>>>>>>>>>>>>> When lines copied from script file and run manually in Terminal
normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ /home/normt/Work/AndroidDevelopment/adt-bundle-linux-x86_64-20140702/sdk/platform-tools/adb devices
* daemon not running; starting now at tcp:5037
* daemon started successfully
List of devices attached

normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ /home/normt/Work/AndroidDevelopment/adt-bundle-linux-x86_64-20140702/sdk/platform-tools/adb kill-server
normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ /home/normt/Work/AndroidDevelopment/adt-bundle-linux-x86_64-20140702/sdk/platform-tools/adb start-server
* daemon not running; starting now at tcp:5037
* daemon started successfully
normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$



The script file:
 
J Bosch
Greenhorn
Posts: 23
MySQL Database PHP Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a different issue.

The script in the original use -- #! /bin/sh -- which worked in the terminal
This one is -- #! /usr/bin/bash

It looks like bash isn't in the /usr/bin/ file
Since  you didn't get the issues with running the adb in your first script, I would recommend staying with #! /bin/sh

Norm Radder wrote:I can not run the script in a terminal either.

normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ ./KillStart_Server.sh
bash: ./KillStart_Server.sh: /usr/bin/bash^M: bad interpreter: No such file or directory
normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ ./KillStart_Server.sh
bash: ./KillStart_Server.sh: /usr/bin/bash^M: bad interpreter: No such file or directory


normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ bash KillStart_Server.sh
: invalid option.sh: line 5: set: -
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
adb: unknown command devices
adb: unknown command kill-server
adb: unknown command start-server
Press ENter


>>>>>>>>>>>>>>>>>>> When lines copied from script file and run manually in Terminal
normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ /home/normt/Work/AndroidDevelopment/adt-bundle-linux-x86_64-20140702/sdk/platform-tools/adb devices
* daemon not running; starting now at tcp:5037
* daemon started successfully
List of devices attached

normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ /home/normt/Work/AndroidDevelopment/adt-bundle-linux-x86_64-20140702/sdk/platform-tools/adb kill-server
normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ /home/normt/Work/AndroidDevelopment/adt-bundle-linux-x86_64-20140702/sdk/platform-tools/adb start-server
* daemon not running; starting now at tcp:5037
* daemon started successfully
normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$



The script file:

 
J Bosch
Greenhorn
Posts: 23
MySQL Database PHP Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this post it sounds like one of the settings Nemo looks for missing when not using the Cinnamon desktop environment.

https://unix.stackexchange.com/questions/336368/how-to-configure-nemos-right-click-open-in-terminal-to-launch-gnome-terminal

 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My console:

normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ bash KillStart_Server.sh
: invalid option.sh: line 5: set: -
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
adb: unknown command devices
adb: unknown command kill-server
adb: unknown command start-server
Press ENter
normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ gsettings set org.cinnamon.desktop.default-applications.terminal exec gnome-terminal
normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ bash KillStart_Server.sh
: invalid option.sh: line 5: set: -
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
adb: unknown command devices
adb: unknown command kill-server
adb: unknown command start-server
Press ENter
normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ sudo update-alternatives --config x-terminal-emulator
[sudo] password for normt:
There is only one alternative in link group x-terminal-emulator (providing /usr/bin/x-terminal-emulator): /usr/bin/gnome-terminal.wrapper
Nothing to configure.
normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ which bash
/usr/bin/bash
normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$



 
J Bosch
Greenhorn
Posts: 23
MySQL Database PHP Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is to for the original problem with Nemo

J Bosch wrote:In this post it sounds like one of the settings Nemo looks for missing when not using the Cinnamon desktop environment.

https://unix.stackexchange.com/questions/336368/how-to-configure-nemos-right-click-open-in-terminal-to-launch-gnome-terminal



Please start a new thread for your bash issue with KillStart_Server.sh
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And thanks for trying to help.  My expectations were obviously too high.  On windows I write batch files all the time.
I was hoping it would be as easy on Ubuntu.  Obviously it isn't.
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When right clicked in nemo and Run in Terminal selected:


There was an error creating the child process for this terminal
Failed to execute child process “/home/normt/Work/AndroidDevelopment/Testing/KillStart_Server.sh”: Failed to execve: No such file or directory


In terminal:


normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ bash KillStart_Server.sh
: invalid option.sh: line 5: set: -
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
adb: unknown command devices
adb: unknown command kill-server
adb: unknown command start-server
Press ENter
normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$


Text of script:
 
J Bosch
Greenhorn
Posts: 23
MySQL Database PHP Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, I forgot to add, you may need to logout and back in or reboot for the gsettings update in Nemo.

Can you logout and then try this again?

When right clicked in nemo and Run in Terminal selected:

There was an error creating the child process for this terminal
Failed to execute child process “/home/normt/Work/AndroidDevelopment/Testing/KillStart_Server.sh”: Failed to execve: No such file or directory



And thanks for trying to help.  My expectations were obviously too high.  On windows I write batch files all the time.
I was hoping it would be as easy on Ubuntu.  Obviously it isn't.


It can be, but some programs are grouped together and when you pull one of them out (Nemo in this case) unexpected things may happen.


 
Marshal
Posts: 4510
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Norm - ignoring the graphical UI, does your script run when run from the command line?
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:Norm - ignoring the graphical UI, does your script run when run from the command line?


When I edit the script file, copy a line, paste it into a terminal and press enter, the contents of the line executes as expected.
I believe I documented that in an earlier post/
 
J Bosch
Greenhorn
Posts: 23
MySQL Database PHP Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
He documented that the scipt executes but has multiple runtime errors.

normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ ./KillStart_Server.sh
bash: ./KillStart_Server.sh: /usr/bin/bash^M: bad interpreter: No such file or directory

 
Ron McLeod
Marshal
Posts: 4510
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does this do what you are expecting (from the command line) ?

Create the script (just copy and paste):
Make script executable:
Run script:
 
Ron McLeod
Marshal
Posts: 4510
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

bash: ./KillStart_Server.sh: /usr/bin/bash^M: bad interpreter: No such file or directory


That control-M character is going to mess things up.  Did you create the script in DOS/WIndows and copy to Linux?
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Restarted PC


normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ ./KillStart_Server.sh
bash: ./KillStart_Server.sh: /bin/sh^M: bad interpreter: No such file or directory
normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$ bash KillStart_Server.sh
: invalid option.sh: line 5: set: -
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
adb: unknown command devices
adb: unknown command kill-server
adb: unknown command start-server
Press ENter
normt@norm-HP-EliteDesk-800-G2-DM-35W:~/Work/AndroidDevelopment/Testing$



In nemo rightclick, Run in terminal


There was an error creating the child process for this terminal
Failed to execute child process “/home/normt/Work/AndroidDevelopment/Testing/KillStart_Server.sh”: Failed to execve: No such file or directory

 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the control-M character in hex?  
I have copied some of the original bits from a Windows system, but most of it I have entered on UBuntu
 
Ron McLeod
Marshal
Posts: 4510
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Control-M is the CR character: 0x0D
 
Ron McLeod
Marshal
Posts: 4510
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's how things look on my Ubuntu installation:

My environment:

Script contents::
Run script:

Here's launching from GDM (sorry for the poor quality I don't have any screen cap capability - used camera):
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ron. I started a new script file with the first line and then copied into it the command lines from the other script file and it now works.


Now to solve the offline problem:

+ /home/normt/Work/AndroidDevelopment/adt-bundle-linux-x86_64-20140702/sdk/platform-tools/adb devices
List of devices attached
emulator-5554 offline

+ /home/normt/Work/AndroidDevelopment/adt-bundle-linux-x86_64-20140702/sdk/platform-tools/adb kill-server
+ /home/normt/Work/AndroidDevelopment/adt-bundle-linux-x86_64-20140702/sdk/platform-tools/adb start-server
* daemon not running; starting now at tcp:5037
* daemon started successfully
+ read -p 'Press Enter'
Press Enter



The new, working script file:



That's it for today.  I'll try again tomorrow.
Thanks everyone.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Bash language lacks some features commonly found in more modern programming languages, such as strong typing, object-oriented programming (OOP) support, and advanced data structures. However, Bash is primarily designed as a shell scripting language for automating tasks and interacting with the command line, so its simplicity and focus on system administration make it well-suited for certain use cases.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
EH: welcome to the Ranch That sounds like a useful guide to Bash.
reply
    Bookmark Topic Watch Topic
  • New Topic