Score:0

Two identical bash scripts in the same directory behave differently. What am I doing wrong?

ph flag

I'm just starting on Ubuntu, trying to figure things out. I'm a little confused.

Short version of my questions:

A) Making my bash scripts executable doesn't seem to be working reliably. It just inexplicably won't work sometimes, even when using the same steps on identical scripts in the same directory.

B) When I can get the executability to work, sometimes two identical scripts seem to behave differently. One does its job as intended, the other throws a "Command not found" Error notification, despite both being the same scripts with different names in the same directory.

------(More details)--------

My steps for making scripts executable:

  1. Right click on the file and check Properties>Permissions>"Allow executing files as program." (This doesn't seem to do anything, but I do it anyway. Whenever I try to execute the script after this step, nothing happens.)

  2. Run "chmod +x " in the terminal.

I have got this to work on two different scripts, but on no others. I have no idea what I'm doing wrong. When executability isn't working, I can run the script through the terminal, and it works just fine.

Here's an example of the script I'm trying to run:

#!/bin/bash

cd Desktop/Projects/Zemmings\ V3/NeoLemmix_V12.12.1
wine NeoLemmix.exe

This script works, and is executable. Now I want to duplicate it and change the paths and programs for different windows apps.

I copy and paste the file, change the name, run through the executability steps above, double click it, and I get an error saying "Command not found". However, this is before changing the script, so it should do exactly the same thing as the original. Despite having identical contents, it give an error while the original still works.

So, if anyone has an answer or tip for me, let me know.

-------(Summary of questions)------------

Why does checking Properties>Permissions>"Allow executing files as program." on a file seem to do nothing?

Why doesn't "chmod +x " work sometimes?

Why are two identical scripts in the same directory behaving differently?

Thanks!

mook765 avatar
cn flag
Confusing, you say executability isn't working but you can obviously execute your script, how does this go together? You should replace the relative path in the cd-command in your script with absolute path.
Martin Thornton avatar
cn flag
Executability *is* correctly set, as terminal works fine, so something different is wrong. This seems to only be about running a script from a file manager. Which one, and also which type of Ubuntu and version are you using? Also, if the only difference really is the name of the files, those exact names might be a clue.
waltinator avatar
it flag
What's the underlying filesystem?
Jeff Schaller avatar
ru flag
Is your editor saving the file with Windows-style line endings? (carriage return + newline instead of just newline)
zanzindorf avatar
ph flag
@mook765 The goal is to launch the scripts from my desktop, not the terminal. It's a time-saving thing. It's the executability from the desktop that's not working. As for the paths, I sort of thought they were absolute. Do they just need a / at the beginning of the paths? I thought relative paths used the . and .. thingies.
zanzindorf avatar
ph flag
@MartinThornton I think it's the default one that comes with default Ubuntu. The about window says it's name is just "Files". I'm running Ubuntu 20.04.2 LTS if that helps. I also have something called "FileManager-Actions" which has a nautilus icon. I tried duplicating the script, deleting the original, and renaming the copy what the original was named, but was met with the same error.
zanzindorf avatar
ph flag
@JeffSchaller I am not sure. I am using gedit, which I believe came with Ubuntu. How would I check that? Also, whichever it is, the line ending are 100% consistent with both copies of the script since I'm copy/pasting the entire file in the file browser.
zanzindorf avatar
ph flag
NEW INFO: I have also stumbled on something new to this. If I open two file explorer windows, one with the desktop and the other with any other directory, and drag the script from the desktop to the other directory, then move it back to the desktop, the dumb thing just starts working. It becomes executable from the desktop by just moving it from one directory to another and back again. How? This is a workaround I guess, but it's kinda annoying. Is there a fix to this?
Score:0
ph flag

The issue I think is that the default desktop is just horrendous. While researching a separate issue, it seems there are numerous issues with the default desktop, and some people just recommend using a different extension for it entirely, which is what I'll do. I switched to "Desktop Icons NG" and everything works perfectly now.

I can simply check "Allow executing files as program" in permissions, and it now works without issue thanks to the new desktop extension. I can also now drag and drop files on my desktop into apps and file browsers. All is good now. Sorry this isn't a fix, it's a workaround, but I think this is simply a bug or an oversight (based on other discussions I found) which will be patched eventually. So I think the only real solution is to wait until it's fixed or use this workaround.

Another possible solution I saw was to disable the experimental view for the file browser, but that did not work for me.

To install the alt desktop extension that worked for me: https://ubuntuhandbook.org/index.php/2020/10/enable-drag-drop-desktop-ubuntu-20-04/

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.