I have a batch file that sets up my environment by opening a number of "git bash" shell windows. This works perfectly apart from one annoying feature where if you press Ctrl C (or send any other Term signal) the whole bash window will close.
I want the window to behave as if it has been opened normally and so when it receives a term signal it goes back to the bash prompt.
Here is the current contents of my setup.bat file:
C:
cd \project\
start "" "%SYSTEMDRIVE%\Program Files (x86)\Git\bin\sh.exe" --login -i -l -c "source ali.sh && mvn spring-boot:run"
cd \project2\
start "" "%SYSTEMDRIVE%\Program Files (x86)\Git\bin\sh.exe" --login
Note that the first start command runs maven and when i want to restart the command (press Ctrl+C) it closes the whole window.
The second start command creates a new bash window in that directory which works like a normal bash window even with Ctrl+C, BUT I want it to have run a command at the start.
Is this possible?
Many thanks for all your help
Something like this might work for you:
C:
cd \project\
start "" "%SYSTEMDRIVE%\Program Files (x86)\Git\bin\sh.exe" --login -i -l -c "sh -c 'source ali.sh && mvn spring-boot:run; exec sh'"
The trick is wrapping the command in:
sh -c '...; exec sh'
Where sh is your shell, might be bash.
You might actually to able to just suffix each command with: exec sh, eg:
start "" "%SYSTEMDRIVE%\Program Files (x86)\Git\bin\sh.exe" --login -i -l -c "source ali.sh && mvn spring-boot:run; exec sh"
Related
I am trying to run rsync from a batch file. The command is
SET CMD="rsync -P -rptz --delete -e 'ssh -i /root/.ssh/CERTIFICATE.pem' SOURCE_ADDRESS /mnt/c/Users/MYNAME/IdeaProjects/PROJECT/SUBFOLDER/SUBFOLDER/SUBFOLDER/SUBFOLDER/LASTFOLDER"
bash %CMD%
This works fine if I run the command after typing bash, but when I run the command from cmd with the bash precursor it says No such file or directory.
Additionally, when playing around and trying to debug bash ends up hanging... i.e. if I open bash I get no prompt, just a blinking cursor.
Any help is appreciated.
To run a command with bash you need to use the -c option
bash -c "%CMD%"
Without it the first non-option parameter will be treated as a *.sh shell script, which rsync isn't and will cause an error
If arguments remain after option processing, and neither the -c nor the -s option has been supplied, the first argument is assumed to be the name of a file containing shell commands.
Note that the cmd in Windows is not DOS even though they have a few similar commands. The rest are vastly different
The following bash script is suppose to open 2 new terminal tabs then execute respective commands:
mate-terminal --tab -e "cd ~/ece344/root; sys161 -w kernel" --tab -e "cd ~/ece344/root; cs161-gdb kernel"
The script does open 2 new tabs however both tabs display the following error:
There was an error creating the child process for this terminal
Failed to execute child process "cd" (No such file or directory)
Ps. The answer should work with mate-terminal.
I don't have mate installed but I would try :
mate-terminal --tab -e "/bin/bash -c 'cd ~/ece344/root; sys161 -w kernel'" --tab -e "/bin/bash -c 'cd ~/ece344/root; cs161-gdb kernel'"
The idea is that "-e" would want to execute a command that probably run inside the window instead of a default shell, so from the error I understand that "cd" is not a real program in an expected location (since 'cd' is in the PATH shouldn't be a problem.
So my example would provide a full path to a shell "/bin/bash" that would then execute the commands you want.
I'm trying to see what the output of a command would be if I were in a login shell, without having to go into a login shell. I've tried several variations of
zsh --login -c "alias"
But none of my aliases get shown; are --login and -c incompatible?
To test the difference between zsh --login -c "alias" and a normal login shell, you can/should add the -x option to see what the shell is up to.
When I run zsh -x --login -c "alias", then it processes /etc/zprofile.
When I run zsh -x --login, then it processes /etc/zprofile and /etc/zshrc.
I don't normally use zsh, so I don't have any personalized profile or start up file for it, but it seems plausible that it might look for (but, in my case, not find) ~/.zprofile and ~/.zshrc too.
I created trivial versions of those files:
$ echo "echo in .zprofile" > ~/.zprofile
$ echo "echo in .zshrc" > ~/.zshrc
and sure enough, they're processed. Further, the -c command with --login processed the .zprofile but did not process the .zshrc file.
Thus, using -c "alias" after the --login suppresses the processing of /etc/zshrc and ~/.zshrc. If you want those executed even so, you need to use something like:
zsh --login -c "[ -f /etc/zshrc ] && . /etc/zshrc; [ -f ~/.zshrc ] && . ~/.zshrc; alias"
Using -x to debug login processing is often informative.
It's nice that modern shells provide a command line option to induce login processing. I still have a program (which I don't use any more) that runs a login shell the old-fashioned way, by adding a - before the shell name in argv[0]. Thus, running -ksh would trigger login processing; the login program would run the login shell with the - at the start.
I need to open a new terminal tab and execute multiple commands on it, how can I do it. I have already tried the following,
gnome-terminal --tab -t "X" -e "cd ~/Desktop/terminal_test;mkdir test"
Here I need to cd into a new directory and create a new folder.
Try this:
gnome-terminal -x bash -c "cmd1; cmd2; …cmdN; exec bash"
You can use gnome-terminal. The script below will open 3 tabs running the respective commands..
tab="--tab"
cmd01="bash -c 'ls';'pwd';bash"
foo=""
foo+=($tab -e "$cmd01")
gnome-terminal "${foo[#]}"
exit 0
I already know how to open a terminal in a bash with gnome-terminal and execute a program:
gnome-terminal -e ./OpenBTSCLI
But I also need that once open that program in the new terminal, write another command inside.
When a I tried to use echo, the message appear in the terminal where I run the bash.
I tried: gnome-terminal -e "bash -c './OpenBTSCLI && echo message'" that I find online but its not working, it only do the first part.
Anyone have an idea of how to resolve this? Thank you
I think it does the second command as well, but the new terminal closes as soon as the command's finished, so you don't see it. I reversed the order of quotes and added a 1s sleep at the end to allow seeing the echo.
gnome-terminal -e 'bash -c "./OpenBTSCLI && echo message && sleep 1"'