Xfce Forum

Sub domains
 

You are not logged in.

#1 2022-06-20 08:06:47

SpongB0B
Member
Registered: 2022-06-01
Posts: 16

[Solved] Run .sh interactively

Hi everyone,

I would like when double click on a .sh file to run it interactively , is it possible ?

At the moment when I double click on it's running in the background (aka non-interactively)

The best method would be to edit the .sh file (like I can choose which one need to be interactive or not..)

Thanks.

Last edited by SpongB0B (2022-06-20 11:59:21)


Linux noob, plz be kind big_smile

Offline

#2 2022-06-20 09:04:21

SpongB0B
Member
Registered: 2022-06-01
Posts: 16

Re: [Solved] Run .sh interactively

I've tried this

if [ -z "$PS1" ]; then
        echo This shell is not interactive
        echo -e "$(pwd)/$BASH_SOURCE \n"
        xfce4-terminal -T "test" -x $BASH_SOURCE
        exit
else
        echo This shell is interactive
        echo -e "$(pwd)/$BASH_SOURCE \n"
fi

But this launch an infinite / loop a new terminal hmm


Linux noob, plz be kind big_smile

Offline

#3 2022-06-20 09:37:20

KBar
Member
Registered: 2021-11-05
Posts: 689

Re: [Solved] Run .sh interactively

First off, you need to explicitly tell Thunar to execute shell scripts instead of opening them:

xfconf-query --channel thunar --property /misc-exec-shell-scripts-by-default --create --type bool --set true

Next, you need to create a .desktop entry for it and enable running in a terminal. The default Menu Editor app will let you do this easily.

The interactivity itself will depend on the utility (i.e. command) you're invoking.

If your scripts handles this and waits for user input (with read), then you'll be able to interact with the script. If it's just a simple command, such as:

cp file1 file2

then of course you won't get any interactivity at all.

EDIT: another way is to put

xfce4-terminal --hold --command='command'

in your script. This will open a terminal window whenever you launch the script and be kept open until you close it.

Last edited by KBar (2022-06-20 09:44:59)


Remember to edit the subject of your topic to include the [SOLVED] tag once you're satisfied with the answers or have found a solution (in which case, don't forget to share it as well), so that other members of the community can quickly refer to it and save their time. Pretty please! tongue

Offline

#4 2022-06-20 11:59:10

SpongB0B
Member
Registered: 2022-06-01
Posts: 16

Re: [Solved] Run .sh interactively

Thank you @KBAR !

I made some test and I came up with this (work well in my case)

if  [ $WINDOWID -gt 0 ] ; then 
        echo "launched from terminal $WINDOWID"
else
        coproc xfce4-terminal -T "Icon launch" -x $BASH_SOURCE
        exit
fi

Linux noob, plz be kind big_smile

Offline

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

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.009 seconds, 8 queries executed - Memory usage: 527.6 KiB (Peak: 528.52 KiB) ]