Windows Terminal showing .bashrc commands or process on command execution - windows

whenever I execute a bash command, it shows the process or all the commands in the .bashrc file.
It didn't show before, but it happened after I put 'set -x'. Currently I don't have 'set -x'.
Thanks in advance.

Related

WSL closes abruptly when I execute a windows command after sourcing a bash script containing the option `set -e`

Steps to reproduce.
Please note, I am using WSL (Ubuntu 18) version 1.
Windows version 1909 (OS Build 18363.900).
Create a dummy bash script foo.sh containing the option set -e.
#!/bin/bash
set -e
pwd
Execute the following commands in WSL.
$ source foo.sh
$ explorer.exe .
After I execute the second command explorer.exe . WSL closes abruptly.
I just tried it out, and indeed: When I run explorer, the explorer Windows opens in the background, and the process which starts the Explorer returns with exit code 1. I don't know why Microsoft in their infinite wisdom decided to implement it in this way.
Of course, having set -e in an interactive shell is insane. I suggest to unset it. If, the scenario is not an interactive shell (this is not entirely clear from your question), but you run the commands from inside a script, and you do want to stick with -e, start the explorer with
explorer.exe || true
to keep the shell running.

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

How to create a shell script to launch 3 terminals and execute a set of commands in each?

Currently, I open 3 terminals ('openocd session','telnet session' & 'gdb session') and execute 'a set of commands' in each terminal every time I flash my image on target.
Is is possible to put this in one shell script file and run at once? (Commands on each terminal are NOT dependent on others; except that the terminals should be opened in the order mentioned above)
Thanks in advance !
Which terminal are you using?
A terminal like xterm can start a program instead of a shell. Simply run
xterm -e 'command args ...'
I use this to start my email client:
xterm -e mutt
If you use a different terminal, consult its manual page. I'm pretty sure there's an equivalent for -e.

Cygwin: Running bash script directly inside dos batch file doesn't work

I've searched over the web and still can't figure it out.
I apologise if this sounds like a lazy whinging cry for help -- I really am at wit's end with this one.
I have a bash script located at:
/cygdrive/k/Linux Scripts/Scripts/filter.sh
I've copied the Cygwin.bat to filter.bat, and changed it as follows:
#echo off
L:
chdir L:\Cygwin\bin
bash --login "/cygdrive/k/Linux Scripts/Scripts/filter.sh amc.txt bmo.txt"
When I run filter.bat by double-clicking on it in Windows Explorer, the console flashes open momentarily and then closes. The script is OK, because it runs from the command line in the Cygwin console.
Is there a way to debug this problem?
Try running the batch file from an already-existing Command Prompt window so you can see any error messages bash might send. I'm guessing it has a problem with "/cygdrive/k/Linux Scripts/Scripts/filter.sh amc.txt bmo.txt" -- as far as it's concerned, that's one argument rather than three. Therefore I would change it to
bash --login "/cygdrive/k/Linux Scripts/Scripts/filter.sh" amc.txt bmo.txt

run terminal commands from quicksilver

I know there is a Terminal plugin for quicksilver but I would invoke terminal commands which basically just runs in the background and never popups a terminal window. is that possible?
UPDATE:
I have the following code in my applescript but its giving me an error:
do shell script "/path/to/shell.sh blah"
error:
curses.setupterm()
_curses.error: setupterm: could not find terminfo database
In Quicksilver you can use the action "Run Command in Shell", which is part of the "Terminal Module". The command is run without showing a window. Search on the quoted terms and you'll find some examples.
Applescript is the simple solution, see:
http://developer.apple.com/library/mac/#technotes/tn2002/tn2065.html
Sample:
do shell script "ifconfig"
do shell script "ifconfig" user name "Anne" password "p#ssw0rd" with administrator privileges
Automator can also run shell scripts in the background.
If you are familiar with XCode, you can use NSTask with Objective-C.
Hold on a sec, is your shell script a bash shell script? In your first line do you have:
#!/bin/bash
If not, add that line to your script.
Also instead of just
do shell script "/path/to/yourscript.sh"
consider this:
do shell script "/bin/bash /path/to/yourscript.sh"

Resources