0

I have a bash script that runs a program which generates files (into the current directory it was run from), then the bash script checks for them, and their sizes.

When I run this script from the terminal, everything works fine, the files are created, found, and reported on.

The problem is that this is supposed to be basic user friendly, and needs to be clickable to run. The script runs when clicked, however, the files don't seem to be generated (maybe they are somewhere else?) and therefore the report is failed as the files aren't found.

In this script, I do a cd ~/path/to/location before calling the program.

#!/usr/bin/env bash
cd ~/path/to/location
./someprogram
if [ touch output.txt ]; then
  echo "FILE EXISTS"
fi
  • What desktop environment do you use? It's probable that the environment is not configured to execute a shell script when double-clicked. It's a little different from Windows, and it makes it safer in my opinion. You probably can make a myscript.desktop file which can execute whatever you want. See /usr/share/applications/firefox.desktop or similar for an example desktop file. – bgStack15 Aug 31 '16 at 13:11
  • I'm using KDE on fedora 7. The script runs, as I have other things in that script that work fine, it's just that the file isn't found. I'll take a look at a .desktop file and see if doing that might help – DOleary Aug 31 '16 at 13:24
  • It's possible KDE is not configured to just run a shell script if you double-click it in a file manager. The best way I know of to get a desktop environment to easily execute a shell script is to make a .desktop file. It's like a Windows shortcut in that you can specify what to run, and the icon, and the name, and so on. – bgStack15 Aug 31 '16 at 13:29
  • I've actually just tested this using a .desktop file and get the exact same result. – DOleary Aug 31 '16 at 13:42
  • I think this must be a working directory issue. Perhaps cd in a bash script run like this doesn't work properly? – DOleary Aug 31 '16 at 13:43
0

It turns out that my environment did not fully copy over using the SHEBANG

#!usr/bin/env bash

by simply defining and exporting the missing environment variables in the script, the script worked fine.

export ENV_VARIABLE_NAME=environment_variable_data

Must have been that the variable was not defined in the bash environment (maybe cshrc or something)

-1

Sorry, my reputation apparently doesn't allow me to comment, though it would have been more appropriate as I'm asking you to check something first.

Anyway, my question is : are you using the same user name when using the console and the GUI ?

You could have been logged in as root when using the console, while your GUI would be logged using another user name, that might not have the needed rights on the folder you're trying to write the files to ?

Then you should ensure you've granted the needed rights to the GUI user (adding the user account to a relevant group, for instance).

That's probably the most common reason for files not being written where you're expecting them when using Linux.

  • Yes, both the terminal and the GUI are operated under the same user. Checked with echo $USER – DOleary Aug 31 '16 at 13:26
  • It may depend on what you're running from the above bash file, but most programs will usually output to the current location and not to the application's. Now i'm thinking about this, most simple scripts will output to the console by default, then you will pipe it to another output file (unless it's an executable program waiting for an appropriate parameter. In the first case, I'm wondering if the "console" would behave differently when called from a GUI. Does a console window briefly show up when you're clicking on your script, BTW ? I'd need to try this, we should have an Ubuntu with KDE. – Z80 Aug 31 '16 at 14:06
  • The other program is in C which generates a file in the directory it is called from. To answer your other question, no console window appears when clicking on the script. – DOleary Aug 31 '16 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.