Tuesday, May 14, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 2181  / 2 Years ago, thu, may 5, 2022, 11:04:54

I created a scriptA.sh on the desktop and make it executable then this was it content:



#!/bin/bash
sudo -u userA bash -c 'PACKAGE_PATH=/home/userA/package1; cd /home/userA/scripts'


I want to double click on this to open terminal and run the two commands in it and keep terminal opened. But what actually happens after double clicking it and choosing to run with terminal option, the terminal opens for a second and then closes itself. I don't know why this is happening, so I'd appreciate if anyone could please advise why this is happening and how to overcome it.


More From » gnome

 Answers
2

You probably want to use gksudo if you want to start it from your Desktop. That will open a window asking you for your password.



#!/bin/bash
gksudo -u userA bash -c 'PACKAGE_PATH=/home/userA/package1; cd /home/userA/scripts'


Also to debug, you probably want to run that script in your terminal first. That way it will not close just after printing some error messages.






Update



One way to do that is to create a file as follow:



/home/user_name/.gnome2/panel2.d/default/launchers/script_name.desktop


Then put something like this in it:



#!/usr/bin/env xdg-open

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon[en_US]=gdu-category-peripheral
Name[en_US]=Receiving fax
Exec=gksu /usr/bin/gnome-terminal
Comment[en_US]=Some description...
Name=My Script
Comment=Start my script
Icon=gnome-panel-launcher


That works great for me, in general. The gnome-terminal accepts parameters so you can change various settings.



Use --working-directory=... instead of your cd ... command. To get specific variables, you probably want to use the --profile=... option.



Exec=gksu -u userA /usr/bin/gnome-terminal --profile=/home/userA/profile --working-directory=/home/userA/scripts


Then create the profile script for the variable:



# In /home/userA/profile
PACKAGE_PATH=/home/userA/package1


Obviously you could add any other alias or anything else you need in the profile script.


[#23111] Friday, May 6, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bathtusain

Total Points: 380
Total Questions: 124
Total Answers: 111

Location: Trinidad and Tobago
Member since Sat, Apr 9, 2022
2 Years ago
;