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.
userA
and by default when I open a terminal its logged in usinguserA
as well.sudo -u userA bash -c
seems unnessecary.