Opening multiple tabs in gnome terminal with complex commands from a cycle

纵然是瞬间 提交于 2019-12-01 19:58:25
Matt Liberty

I just ran into this same problem and came across this post while trying to fix it. If "complex argument" relies upon shell expansion, I believe that you will need to start a shell with the command passed to gnome-terminal. For example:

gnome-terminal \
--tab -e "sh -c 'command \"complex argument1\"'" \
--tab -e "sh -c 'command \"complex argument2\"'"

You can start bash or any other shell instead of sh. For more examples see this stack exhange post.

Not sure this will help out as the post is about a year old, but I had a similar issue scripting gnome-terminal in BASH. My answer is similar to riachdesign, but the escape characters differ. Here's what I did:

gnome-terminal -e bash -c "/home/someprogramtorun /home/user/'$dir'/filetopasstoprogram.txt"

If I didn't add the single quotes around $dir (e.g., $dir vs. '$dir') the line would execute verbatim (i.e., it would not pass the variable's contents into the line).

Hopefully that helps.

AFAIK, you may need to escape the double quotes (or single quotes, whatever you use around $args), like so. ('command \"complex argument1\"' --tab -e 'command \"complex argument2\"')

Have a look at this ruby gem that does exactly that: https://github.com/Achillefs/elscripto

I found the solution: arrays. They can do magic.

# initial arguments
command=(gnome-terminal -e 'command "complex argument"')
...
# add extra arguments
command=("${command[@]}" --tab -e 'command "complex argument2"')
...
# execute command
"${command[@]}"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!