Xfce Forum

Sub domains
 

You are not logged in.

#1 2018-12-19 16:11:26

bathtubs
Member
Registered: 2018-12-19
Posts: 2

Execute bash script and keep terminal window open in any directory.

I have a bash script that I want to use to configure the settings on a new Linux installation using xfce4. I want to be able to double click the script and observe the response of the commands as they are executed in the terminal window. I would like for this script to work regardless of which directory it is in.

I have attempted doing this with a xfce4 launcher with the following code:

[Desktop Entry]
Name=Setup Script
Comment=This Script will Setup the files on the new OS
Exec=$PWD/xfce4-terminal EDH-SETUP.sh
Icon=/
Terminal=true
Type=Application
StartupNotify=true

I have attempted several ways to do this without using a launcher. But most of the people on forums with a similar problem seem to be using the launcher as a work around in xfce.


I can make the launcher code work *if* I specify the exact directory path. However, I need to the launcher to work in the current working directory regardless of what that directory is.

Offline

#2 2018-12-20 05:31:53

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,703

Re: Execute bash script and keep terminal window open in any directory.

Hello and welcome.

I'm not sure exactly what this script does, but your Exec command won't work because the xfce4-terminal binary is usually found in one place on your computer - generally /usr/bin. You can use the "-H" parameter to keep the terminal window open after execution:

Exec=xfce4-terminal -H EDH-SETUP.sh

However, I need to the launcher to work in the current working directory regardless of what that directory is.

What exactly do you mean by this? Does your script need to know the directory that the launcher was executed from?


Mark solved threads as [SOLVED] to make it easier for others to find solutions.
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2018-12-20 13:37:08

bathtubs
Member
Registered: 2018-12-19
Posts: 2

Re: Execute bash script and keep terminal window open in any directory.

I have a computer that is used to perform electrical tests on circuit boards. It uses bash scripts to run those tests that were created by an engineer who no longer works for the company. The computer itself is obscure hardware and runs Linux Mint 17.2. My predecessor probably chose to use Linux Mint running xfce as the OS to run the test scripts probably because Linux Mint was easy to get working on the obscure hardware. And also because he knew how to make bash scripts.

Occasionally, the nature of the testing that we do sometimes causes hardware problems that may break or brick the harddrive and the OS and it's scripts then need to be reinstalled. I have tried making a premade installation image or backup of the OS to restore. But something about the hardware on the computer seems to cause issues. So I am attempting to make a setup / configuration script that will update the package manager, download the necessary programs, copy over the necessary files and edit the sudoers file.

The script would need to be useful for engineers who are not proficient in Linux or scripting. But would be smart enough if they saw an error message output as the script was running that they might trouble shoot through it.

So that is why I would prefer that the window continue to stay open as the script runs.

What exactly do you mean by this? Does your script need to know the directory that the launcher was executed from?

I also need it to work without needing to be placed in a specific directory. If the user places it in the desktop, or the home folder, or some other folder.

Last edited by bathtubs (2018-12-20 15:14:28)

Offline

#4 2018-12-20 23:13:54

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,703

Re: Execute bash script and keep terminal window open in any directory.

bathtubs wrote:

I have a computer that is used to perform electrical tests on circuit boards. It uses bash scripts to run those tests that were created by an engineer who no longer works for the company. The computer itself is obscure hardware and runs Linux Mint 17.2. My predecessor probably chose to use Linux Mint running xfce as the OS to run the test scripts probably because Linux Mint was easy to get working on the obscure hardware. And also because he knew how to make bash scripts.

Occasionally, the nature of the testing that we do sometimes causes hardware problems that may break or brick the harddrive and the OS and it's scripts then need to be reinstalled. I have tried making a premade installation image or backup of the OS to restore. But something about the hardware on the computer seems to cause issues. So I am attempting to make a setup / configuration script that will update the package manager, download the necessary programs, copy over the necessary files and edit the sudoers file.

The script would need to be useful for engineers who are not proficient in Linux or scripting. But would be smart enough if they saw an error message output as the script was running that they might trouble shoot through it.

So that is why I would prefer that the window continue to stay open as the script runs.

The "-H" parameter will do that for you.

What exactly do you mean by this? Does your script need to know the directory that the launcher was executed from?

I also need it to work without needing to be placed in a specific directory. If the user places it in the desktop, or the home folder, or some other folder.

This one is tougher. There doesn't appear to be a way for the launcher to know which directory it was launched from. Your best bet is to place the file in one of the directories in your PATH so that it is easy to locate and execute.


Mark solved threads as [SOLVED] to make it easier for others to find solutions.
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#5 2018-12-21 01:22:02

Misko_2083
Member
Registered: 2015-10-13
Posts: 211
Website

Re: Execute bash script and keep terminal window open in any directory.

%k will print the desktop file name
This will change dir to the directory from which the launcher was launched

cd $(dirname %k)

You can test this with

Exec=xfce4-terminal -H -e "bash -c \"cd $(dirname %k) && pwd\""

Instead of hold -H I usually put bash to keep the terminal running.
But that's a matter of personal preference...

Exec=xfce4-terminal -e "bash -c \"cd $(dirname %k) && pwd; bash\""

Do you want to exit the Circus?
https://www.youtube.com/watch?v=ZJwQicZHp_c

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.012 seconds, 7 queries executed - Memory usage: 546.87 KiB (Peak: 547.71 KiB) ]