How to get Powershell to run SH scripts - powershell

Can someone please tell me how I get Powershell to run .sh scripts? It keeps just trying to open the file i need in Notepad when I run this command:
.\update-version.sh 123
I've added .SH to my PATHEXT environment variable and also added the Microsoft.PowerShell_profile.ps1 directory to the Path environment variable.

PowerShell scripts have a .ps1 extension (along with other supported extensions such as psm1,psd1 etc) it will not run other extensions other than that.

I had also got the same issue when i am trying to run .sh files. The solution is you need to enable bash shell by typing bash.After enabling Bash on Windows, you can run .sh files by typing bash ./fileName.sh. But i have tried through git bash with typing . fileName.sh it worked well. These are the two solutions that I have found, and you can try whatever you wish.

Related

Running a Python file on command prompt launches vscode instead

I'm trying to launch a python script on windows command prompt, but instead of it doing it, it opens the script on vscode instead. I searched the options in vscode and didn't find anything. How can I stop this behavior?
SOLVED
I simply changed the default program for .py files
You need to change the default application for .py files to python.exe.
This will instruct Windows to pass the filename of the python script you're trying to open to python.exe, which will execute it.
python my_script.py
As a bonus, if you change the PATHEXT environment variable to include .py extension. This will allow you to run a python script without prefixing it with python command when working in a shell.
./my_script.py
Python installer does this by default, but if it isn't there, you can add it.

VSCode CLI install extension from local file with powershell

I am trying to use PowerShell to install a VSCode extension from a local file (not from the internet).
When I use Start-Process and give the appropriate file path, it opens VSCode, stalls the script, and does not install the extension. When I close VSCode, the script terminates without error, but still the extensions is not installed.
I need the exact syntax to install a VSCode extension from PowerShell silently (no new window).
I've tried just about every syntax variation.
Thanks
Instead of using Start-Process, call the default name for VS Code: code. VS Code has some nice CLI options when you call this, one of which is --install-extension. Heres an example of what you can call in powershell or in a .ps1 script that would do this:
code --install-extension path/to/extension.ts
or if you have made an extension pack to help automate the install of multiple extensions at once:
code --install-extension path/to/extensionPack.vsix

How can I run jupyter notebook as .sh executable in Ubuntu?

I have a lot of .ipynb file stored in one folder. I have create a .sh file which contain only code jupyter notebook. Then I have change the preference > behavior in nautilus file manager to ask each time. Then when I double click the .sh file the box appear and I select run from terminal. But It is not executing and not opening then jupyter notebook. but if I do with terminal code it works as follows:
chmod +x /path/to/ipynbStart.sh
./ipynbStart.sh
I do the first approach with .bat file in windows and it works fine. I tried a lot But I could not find a solution. Thanks in advance.
It was not that difficult. I just create a new sh file (jupyter-start.sh) with the following command in the project directory I wanted:
#!/bin/bash
clear
sh -c /home/datapsycho/miniconda3/bin/jupyter-notebook
In the third line it's the path to the jupyter-notebook in my system.
Then run the chmod +x jupyter-start.sh to make it executable. Now I can place that file to all my project folders where I need to start jupyter notebook and it will always start in the specific project directory I want.
Now every time I just can execute that program to start jupyter notebook with out writing any thing in the shell.

Script in PATH Mac OSX terminal not working

I have the following script in my /path/to/startupscripts directory, so I can open the emacs GUI with the command 'emacs':
#!/bin/sh
/Applications/Emacs.app/Contents/MacOS/Emacs "$#"
I edited my ~/.bash_profile and added the following line
export PATH=/path/to/startupscripts/emacs:$PATH
However, the script is not working because when I type in 'emacs' into the command line emacs still opens within terminal and not the GUI like I want. Also, when I am in the /path/to/startupscripts directory and I can execute and run the script with
chmod +x emacs
./emacs
but even when I type 'emacs' afterwards it still opens within terminal. I am a bit of a beginner, and I think I am missing something painfully obvious.
The PATH should contain a directory name where your script(s) can be found, not the name of your individual script.
You probably need to source your .bash_profile:
source ~/.bash_profile
No changes made in your profile will be applied unless you source the profile or log out and back in.
Aside from that every looks like it should work.
However you may want to consider just using an alias instead of a script for this. This can be done by adding this to your profile:
alias emacs=/Applications/Emacs.app/Contents/MacOS/Emacs
That's probably a cleaner way to get the functionality you want without adding more to your PATH variable.
I hope that helps! [insert obligatory comment about how you should be using vim and not emacs :P]

Configure Eclipse to use bash login shell for Cygwin toolchain

I have a custom Makefile project in Eclipse and although the build does get run in a Cygwin shell... it does not seem to be a login shell (bash --login) as it doesn't set my environment variables like running cygwin.bat does.
Where in Eclipse can I change the shell command so that it will be a login shell?
What you actually aim with bash --login are your settings from /etc/profile.
Under UNIX you normally have only one login shell and so these settings are inherited by all other shells. Under Windows any Bash window is an isoloated login shell, which leads to missing environment settings when running Bash from tools that run bash simply as command processor.
I had a similar problem with Emacs compile feature. The best solution under Windows is to set the environment variable BASH_ENV to a script. Bash will execute this script when started without -i or --login, so that /etc/profile is not run. Hence the script will setup Bash for non-interactive, non-login shells.
Example:
BASH_ENV=%USERPROFILE%\.bash_env
as user environment variable. The least thing to do in this script is to set PATH as in /etc/profile:
PATH="/usr/local/bin:/usr/bin:${PATH}"
Check the path-settings in /etc/profile as it is created by Cygwin's setup.exe. You may also copy settings from ~/.bashrc or source this script.
Hope this helps.