I am new to linux shell script. I want to write a shell script which will open terminal with multiple tabs. And in each tab it should run one rtsp client app.
i have written this code,
tab="--tab-with-profile=Default -e "
cmd="java RunRTSPClient"
for i in 1 2 3 4 5
do
#
foo="$foo $tab $cmd"
done
gnome-terminal $foo
exit 0
Its executing fine but it will open terminal and immediately it is closing.(I am not getting errors)
If I replaced the line foo=... with gnome-terminal --tab -e $cmd then its working fine but opens independent terminal.
suggest me how to fix this.
thank you
You should always (always!) use an array for building up argument lists in bash.
That is:
#!/bin/bash
# ^^ this has to be bash, not /bin/sh, for arrays to work
cmd=( gnome-terminal )
for ((i=0; i<5; i++)); do
cmd+=( --tab-with-profile=Default -e "java RunRTSPClient" )
done
"${cmd[@]}"
This will give you the exact equivalent of running:
gnome-terminal \
--tab-with-profile=Default -e "java RunRTSPClient" \
--tab-with-profile=Default -e "java RunRTSPClient" \
--tab-with-profile=Default -e "java RunRTSPClient" \
--tab-with-profile=Default -e "java RunRTSPClient" \
--tab-with-profile=Default -e "java RunRTSPClient"
...which is what I understand that you want.
Trying to build a complex command in a string causes Very Bad Things to happen; read http://mywiki.wooledge.org/BashFAQ/050 to understand why.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With