Is there a way to launch Terminal with a prefilled statement? - macos

I want to open a terminal window with a statement. Is there a process I can run that will do this?
For example, I want to run a script that 1. Opens Terminal and 2. has the following statement:
java -version
The user then can press the Enter key to run the statement

One way to do this is by wrapping the command in a .command file that contains a command to read something, such as:
#!/bin/bash
command="java -version"
echo $command
read input
exec $command
...then, make the script file executable by running chmod +x filename.command on the file that you put this in, and run it (e.g. from the Finder or by using open filename.command). This should launch the terminal, print the command, and wait for the user to press Enter before running it.
You will note that since this is a script, you can customize any of the steps above to do whatever you want, e.g. printing more stuff or running other commands.

Related

When program uses Command to open Bash to run a script, Bash closes immediately without running the script

I have a simple, already-working bash script set up to launch specific files with specific programs in the gaming frontend EmulationStation on Windows.
But the frontend routes its actions through a Command Prompt. And when Command is used to run the script through Bash, the Bash shell just opens and then closes immediately.
Here's an image of what shows for the instant before Bash closes.
This is only happening when going through a separate Command Prompt first, such as Windows Command Prompt or Git Command Prompt. Running the script with an appropriate argument directly through the git-bash shell works just fine.
In case you want to see the script for any reason, here it is:
#!/bin/bash
defaultemulaunch="V:/Emulation/.emulationstation/systems/retroarch/retroarch.exe -L "V:/Emulation/.emulationstation/systems/retroarch/cores/bsnes_mercury_accuracy_libretro.dll" \"$1\""
emu1names=(\
"(1999) Fire Emblem - Thracia 776.smc")
emu1launch="V:/Emulation/.emulationstation/systems/retroarch/retroarch.exe -L "V:/Emulation/.emulationstation/systems/retroarch/cores/snes9x_libretro.dll" \"$1\""
gamename=`basename "$1"`
for index in ${!emu1names[*]}
do
game=${emu1names[index]}
if [ "$game" == "$gamename" ]; then
eval "$emu1launch"
fi
done
eval "$defaultemulaunch"
But it's worth pointing out that this is happening when trying to run any bash script when starting the process from a separate Command Prompt.
Note: Git is installed on the hard drive that houses the emulation frontend (V:)---not in the user directory or programs directory of the system's OS/boot drive (C:). I mention this because git-bash's failure at an apparent "login" step except when launched directly feels like it could be a default filepath issue.
Check if that program would still open/close a Windows when executed from the CMD with:
bash -c '/v/path/to/bash/script'
In your case:
set PATH=V:\Emulation\
set GIT_HOME=V:\Emulation\Git
set PATH=%GIT_HOME%;%GIT_HOME%\bin;%GIT_HOME%\usr\bin;%GIT_HOME%\mingw64\bin;%PATH
Then:
cd V:/Emulation/.emulationstation/roms/snes/
bash -c './gamelaunch.sh "./(1990) F-Zero.sfc"'
I usually make a run.bat script which would:
set the correct PATH
launch the correct script
That way, for any of my project, I just type run.
And it runs.

Keep terminal open at the end of bash script

I'm trying to run a bash script from cmd. When I execute the script a new terminal is opened an immediately closed since there is some problem with it. Because its happening so fast I can't read the problem. I'm looking for a way to keep the terminal open once the script exits.
Go horribly Windows-y with this:
read -p "Press any key to continue" x
You can also put a $SHELL in a new line at the end of your script. The window will stay open, no matter from where you open your shell script (e.g. cmd / powershell / etc).
Add bash at the end of the script
It works for me.
to test a .sh script in windows cmd (assuming you have bash installed and in your path environment variable):
cd into parent directory,
type "bash" to enter bash console,
type "./",
type "exit" to exit bash console

Execute commands on new terminal on cygwin

I am trying to execute a script on cygwin terminal.I want to start a new terminal, close the existing one and run the rest of commands present in the script on new terminal.
I have included the command :
cygstart /bin/bash -li
at the end of my file to open a new terminal of cygwin.
But the rest of commands included after :
cygstart /bin/bash -li
are being executed at the previous cygwin prompt only, not the new one.Even i could not figure out how to close the previous terminal.
Cygstart just executes specified program in the new terminal window. Your script just opens new bash shell with cygstart and continues to work. I think you probably must to divide the script by two parts and call second of them via cygstart if it is really necessary. (Although as far as I know, there is a problem with passing of additional arguments to cygstart command.)

How to put a command in a SH file

I'm using wine to open a game and to open the game I must enter the following command in the terminal
cd "/home/brandon/.wine/dosdevices/c:/Program Files/League of Legends/RADS/system"
Then I enter this below
WINEDEBUG=+ntdll wine "rads_user_kernel.exe" run lol_launcher $(ls ../projects/lol_launcher/releases/) LoLLauncher.exe
and then the game normally loads.
Is it possible to put the 1st command and the 2nd command together in an .sh file so I just double click it and everything will be automatic?
#!/bin/bash
cd "/home/brandon/.wine/dosdevices/c:/Program Files/League of Legends/RADS/system"
WINEDEBUG=+ntdll wine "rads_user_kernel.exe" run lol_launcher $(ls ../projects/lol_launcher/releases/) LoLLauncher.exe
If I understand your problem correctly, this should run the two commands through the script.
You also will have to do
chmod u+x name_of_script
before you can run it.

How do you run a command in iTerm when it launches?

I'm working on configuring the iTerm terminal emulator for the Mac to do what I want. Apparently everything is done through what they call "bookmarks." OK, fine. I'm trying to create a bookmark that will open a tab, cd to a certain Rails project, and run the command script/server. What's supposed to happen is that this will launch the server daemon ("Mongrel") and I'll see the output scrolling by every time I look at that tab.
In the config dialog, under "command" I put script/server and under "working dir" I put the project directory.
What happens is that the tab appears for 1/10th of a second then vanishes.
Recalling a similar problem I had with the Unix screen command, I tried putting a "command" of bash -c 'script/server' but the result was identical.
You're running into that problem because your script runs and then terminates. All you need to do is put a read or something equally sophisticated to say "Press any key to complete script and close window...." at the end of the script.
update
I wrote this test script:
$ cat echoscript
#!/bin/bash
echo "Hello world"
read text
$
I created a bookmark so:
name: test
command: /Users/chasrmartin/echoscript
Working directory: /Users/chasrmartin
When I open the bookmark test, I see my "Hello world", and it waits until I type return. When I type return, it goes away.

Resources