bash command to run a program in a new command line window - bash

I want to run a program from inside a bash script, such that it opens in a new command line window. How can I do this?

That really depends on the GUI you are using. Try some of the below for executing an ls command.
With gnome-terminal:
gnome-terminal -x bash -c "ls; bash"
(taken from http://www.linuxquestions.org/questions/programming-9/is-command-line-invocation-of-gnome-terminal-to-run-more-than-one-command-possible-789599/)
With xterm:
xterm -e "ls; bash"
(taken from http://ubuntuforums.org/showthread.php?t=760006).
For konsole, take a look here:
http://mandrivausers.org/index.php?/topic/28128-opening-tabs-in-konsole-from-script/
or here:
http://lwn.net/Articles/88410/

xterm -e 'program to be run'
Your terminal may have a different switch than -e, but I don't know what your terminal is.

Related

bash interact just once

I want to write a script for Ubuntu, which open a terminal-emulator, which only allows users interact with it only once. After finish running user's first command typed in, the terminal close on itself automatically, which is kind of like Win+R on windows OS.
How should I do that?
I try script like gnome-terminal -- bash -c "read cmd && $cmd", but there's two problem:
No auto-complete on user inputting commands;
Commands from .bashrc, .bash_aliases are not recognized.
You can try :
gnome-terminal -- bash --rcfile <(cat ~/.bashrc; echo 'PROMPT_COMMAND="PROMPT_COMMAND=exit"')
I don't have Ubuntu to test at the moment, but bash ... part worked.

How do I make a script start up a terminal and run a text line on bash?

I am pretty sure its simple, I just couldn't find an answer that fit bash or linux. Here is my script, its really short:
gnome-terminal
echo "you heff bin hackt"
$SHELL
I wanted to make it just as a quick joke but I am having issues with it. It opens the terminal but does not run the text line. What is going wrong with it?
You can use the --command option
gnome-terminal --command="/bin/echo 'msg'; $SHELL"
edit
--command is on deprecation path, so -- is a better option
gnome-terminal -- /bin/bash -c "/bin/echo 'msg'; $SHELL"
If you want to show the text if you open any new terminal session, you could add your command to the .bashrc file:
echo 'echo "message"' >> ~/.bashrc

Lua Mac os.execute open Terminal and run command

I need to open the Mac Terminal and run some commands with os.execute in Lua
export VAMP_PATH=/path/to/plugin/directory
cd /path/to/script
./sonic-annotator -l
EDIT: got it to work without terminal with this
os.execute('export VAMP_PATH="'..script_path..'sonic/mac64/vamp"; cd "'..script_path..'sonic/mac64/"; ./sonic-annotator -d vamp:qm-vamp-plugins:qm-barbeattracker:beats -w csv "'..filename..'"')
To answer your actual question, you can start a Terminal and run some bash commands in it like this:
os.execute("osascript -e 'tell application \"Terminal\" to do script \"cd /Users/mark && ls\"'")
But, as I said in the comments, you don't necessarily need a Terminal to run a script, so you can just run a command like this:
os.execute("export V=fred; cd /Users/mark && ./SomeScript.sh")
If you are running a script because you just want the user to see the output of the script, it is often easier and involves far less quoting if you run your command and pipe the result to open -f like this, which displays the output in a text editor:
os.execute("cd /Users/mark; ls | open -f")

How can I open shell and then execute a command inside it

What I want is to open default shell, then call another and execute a command there.
Was trying something like this:
c:/Windows/System32/bash.exe -c "zsh & zstyle"
or
cmd /k "c:/Windows/System32/bash.exe -c zsh" & zstyle - this open shell but doesn't run a commands
or
c:/Windows/System32/bash.exe -c "zsh -c 'zstyle'"
Currently I am using a cmder/conemu terminal for windows.
Unfortunately, passing a startup to command to zsh with -c and keeping it open for interactive use (with -i) doesn't work.
Disclaimer: The following solutions were tested from a regular Command Prompt (cmd.exe), not cmder/conemu, though I'd expect them to work there too.
To try them from PowerShell (v3+), insert --% as the first argument after (right after bash.exe).
Here's a workaround:
c:/Windows/System32/bash.exe -c "zsh -c 'zstyle' && exec zsh -i"
Note that command zstyle is executed in a different, transient zsh instance, so this approach won't work for commands whose purpose is to modify the environment of the interactive shell that stays open.
If that is a requirement, things get more complicated (this solution courtesy of this answer):
c:/Windows/System32/bash.exe -c "{ { echo 'zstyle'; echo 'exec 0<&3-';} | zsh -i; } 3<&0"
Note, however, that both commands being executed will be printed before their output, if any, is shown, preceded by the prompt - as if the commands had been typed interactively.

How can I run a command in a remote xterm?

In a cshell script, I spin-out an xterm. From the shell where the script is executed from, I wish to execute a command (eg: banner master win) in the xterm that has been spun out from the script.
Can you suggest me a way to do that?
Do you think finding for xterm's paid would help me in this case?
Just use the -e argument to the xterm when you start it
From the output of xterm --help
[-e command args ...]
So running the following will launch an xterm to run the watch command against the date program, with a suitable title:
xterm -T "Date" -e watch date &

Resources