I want to execute a C program in separate terminal, I've tried this command,
gnome-terminal -x ./test
and
gnome-terminal -e test
But it opens a new terminal and before giving me output, it just vanish.
How could I solve this issue using gnome-terminal?
Thanks in advance
This might be what you search:
gnome-terminal -e "bash -c \"!!; exec bash\""
or (shortly):
gnome-terminal -x sh -c "!!; bash"
It opens gnome-terminal with your last command (!!) executed and it stays open with the command output in the shell, even with an interactive command like top or less...
In your case its:
gnome-terminal -e "bash -c \"./test; exec bash\""
or
gnome-terminal -x sh -c "./test; bash"
Related
I am trying to use an .sh script to start a terminal when ubuntu boots. Gnome-terminal successfully starts up but when commands start executing such as (roscore, roslaunch or rosrun) it displays an error as follows: "bash: roslaunch command not found". Is there any way to fix this problem or any other way to start launch files of ROS with a visible terminal at start?
This is how my .sh file looks like
#!/bin/bash
gnome-terminal --geometry=40x40 \
--tab --title="roscore" -e "bash -c \"source ~/.bashrc;roscore;exec bash\"" \
--tab --title="navigation" -e "bash -c \"sleep 38;roslaunch navigation.launch;exec bash\"" \
--tab --title="robot" -e "bash -c \"sleep 28;roslaunch robot_config.launch;exec bash\""
Are you sourcing ros setup.bash file (source /opt/ros/$ROS_DISTRO/setup.bash)? If not just add it to ~/.bashrc file
How can I implement the following scenario in Ubuntu Linux?
I want to go to my console, then execute ./startdev.sh and then
1) Terminal 1 pops up, starts /home/foobar/bla1.sh
2) Terminal 2 pops up, starts /home/foobar/bla2.sh
3) Terminal 3 pops up, starts /home/foobar/bla3.sh
I already figured that the command "gnome-terminal & disown" starts a new terminal.
However, until now, I don't know how to run a command in that terminal.
I accept any answer that gives me either the entire implementation for startdev.sh or a list of commands that I can use.
Thank you!
Try this content for startdev.sh:
#!/bin/bash
gnome-terminal --command=/home/foobar/bla1.sh & disown
gnome-terminal --command=/home/foobar/bla2.sh & disown
gnome-terminal --command=/home/foobar/bla3.sh & disown
But it is not clear for me why you need to disown the launched processes.
Try this script
If you need to simultaneously pop all terminals
#!/bin/bash
gnome-terminal -e "bash -c '/home/foobar/bla1.sh; sleep 10'" | gnome-terminal -e "bash -c '/home/foobar/bla2.sh; sleep 10'" | gnome-terminal -e "bash -c '/home/foobar/bla3.sh; sleep 10'"
else if you need to run commands one by one terminal then .,
#!/bin/bash
gnome-terminal -e "bash -c '/home/foobar/bla1.sh; sleep 10'"
gnome-terminal -e "bash -c '/home/foobar/bla2.sh; sleep 10'"
gnome-terminal -e "bash -c '/home/foobar/bla3.sh; sleep 10'"
this script will open multiple terminals and execute the command given within the quotes and i have used sleep to hold the terminal from exiting if not added gnome-terminal will execute command and exit immediately.
I want a script,which after executing will open multiple tabs and a specified command will run on every tab.Basically that command is ssh i.e. for connecting to other machines.
you can try something like this;
gnome-terminal --tab --title "server1" -x bash -c "ssh -t user1#host1 'nohup yourCommand'" --tab --title "server2" -x bash -c "ssh -t user2#host2 'nohup yourCommand'"
When I type:
gnome-terminal --tab -e 'ls' --tab -e 'ls'
Two new tabs opens in a new terminal window with the 'ls' results, but the prompt is not displayed and no more useless. I want to continue working in these tabs normally.
Can you help me? :)
Try this:
gnome-terminal --tab -e 'ls; exec bash'
Or
gnome-terminal --tab -e 'bash -c "ls; exec bash"'
When I use the following command, everything works as expected (a new gnome-terminal is open, the current working directory is changed and the terminal remains open):
gnome-terminal -e "bash -c 'cd /';$SHELL"
# ↑
# no space character here
But when I use:
gnome-terminal -e "bash -c 'cd /'; $SHELL"
# ↑
# note the space
I can see a terminal that opens, but I can't see if the current working directory is changed or not because the terminal it closes immediately.
My question is: why this is happening; how can be wrong if I put a space in the second case?
In the first case, gnome-terminal executes
bash -c "cd /;/bin/bash"
in the second case, it runs
bash -c "cd /;" /bin/bash
The first case means "evaluate cd /;/bin/bash", which will cd and run an interactive shell.
The second case means "evaluate cd /; with $0 set to /bin/bash", which will run cd and then exit.
gnome-terminal does its own parsing of the command given to it, using g_shell_parse_argv, which apparently doesn't consider ; to be a word separator, so if a ; is adjacent to a non-whitespace character, it is considered to be part of that non-whitespace character's word.
This can result in surprising behavior if the command you pass to gnome-terminal has shell metacharacters in it.
I used strace on the gnome-terminal process to see what it does. The first command
gnome-terminal -e "bash -c 'cd /';$SHELL"
results in gnome-terminal running the following command
execve("/bin/bash", ["bash", "-c", "cd /;/bin/bash"])
The second command
gnome-terminal -e "bash -c 'cd /'; $SHELL"
results in gnome-terminal running the following command
execve("/bin/bash", ["bash", "-c", "cd /;", "/bin/bash"])
That being said, you should also note that a command such as bash -c 'cd /' will not have a lasting effect on the working directory of any command run after it. So I think that the first command you typed got the desired result only because of the gnome-terminal parsing misfeature, and a more robust way of writing it would be
gnome-terminal -e "bash -c 'cd /;$SHELL'"