(For Ubuntu 12.04) The problem here is that with your script bash will open a gnome-terminal and then executed the command in you current terminal instead of the newly opened one (if that's what you are actually trying to do.)
Note: Also as suggested by @unorthodox grammar &
should be used at the end of the command that you don't want to wait for (allowing them to run in background). However, interestingly that's not the problem at least in Ubuntu 12.04. But perhaps in other Ubuntu flavors this might be an issue.
You can execute the commands in the newly opened gnome-terminal by using the following command:
gnome-terminal -e "ls -a /examplefolder"
or
gnome-terminal --command "ls -a /examplefolder"
However, this would close the terminal as soon as the commands are executed and if you want to see the result of those command you won't be able to. Note that gnome-terminal is not designed for this use case (seeing the results in a newly opened gnome-terminal from script). One of the work around as defined in this nice answer is the following:
Let gnome-terminal run bash and tell bash to run your commands and then run bash
gnome-terminal -e "bash -c \"echo foo; echo bar; exec bash\""
or
gnome-terminal -x bash -c "echo foo; echo bar; bash"
The exec bash at the end is necessary because bash -c
will terminate once the commands are done. exec
causes the running process to be replaced by the new process, otherwise you will have two bash processes running.
You can refer to this answer for further workarounds.
gnome-terminal -x bash -c "echo foo; echo bar; bash"
– TuKsn Jun 02 '14 at 08:53