I'm running a shell script.sh
which is supposed to open terminal and then run some commands in this opened terminal. What happens is that the terminal starts but the following commands are not executed in this terminal. If anyone can please tell me how after openening the terminal through this script.sh
to run in it some other commands.
This is is my script.sh
file:
#!/bin/bash
gksu -u userA /usr/bin/gnome-terminal PACKAGE_PATH=/home/userA/package1; cd /home/userA/scripts
so the first command gksu -u userA /usr/bin/gnome-terminal
opens a terminal instance, I'm asking how to run the two following commands PACKAGE_PATH=/home/userA/package1
and cd /home/userA/scripts
in this opened terminal instance using the script.sh
EDIT:
after applying muru's suggestion this is what I used:
gnome-terminal -x sudo -u userA bash -c 'PPACKAGE_PATH=/home/userA/package1:/home/userA/package2:$PACKAGE_PATH; cd /home/userA/scripts; source varset.sh; bash'
but it is not run in the same sequence I put it.
The first line appears in the terminal is a message which is found in variables.sh (although this should be the third command to run) and the other thing is that none of the variables that should be set using this varset.sh
is set, for example when I use echo $var1 (which is found in variables.sh) is display nothing which means the variables is not set the only thing that works in variables.sh is the echo message displayed.
The second line that appears in the the directory is the terminal working directory which is set to the /home/userA/scripts
.
The third thing is that this command PACKAGE_PATH=PACKAGE_PATH=/home/userA/package1:/home/userA/package2:$PACKAGE_PATH
which sets the $PACKAGE_PATH variable is not working.
So if anyone could please advise how to run this command in this sequence and to set the variables on the first command and variables in the varset.sh
shell file.
gnome-terminal -x sudo -u userA bash -c 'PACKAGE_PATH=/home/userA/package1; cd /home/userA/scripts; bash'
instead of running the terminal itself as another user.