Run .sh shell script file from VSCode PowerShell CLI? - powershell

What I've tried:
bash scripts/shell/test.sh
sh scripts/shell/test.sh
These were the results:
The term 'bash' is not recognized...
The term 'sh' is not recognized...

This may sound daft, but if you are in a Powershell shell how will that shell know where to find the bash or sh interpreter? Is it already defined in the environment?
In my opinion you're going to have to tell the Powershell terminal where it should find the bash/sh interpreter, i.e. call bash it with the full pathname

i read you're suppose to use chmod +x scriptname.sh before using the bash command

Related

Powershell Core - How to make linux file type executable

Is there a powershell core equivalent to the following bash command when running on linux:
sudo chmod +x myexec
I want to make this file type executable. This is simple to do using bash but I would prefer to use powershell if it is possible.
So far I am using the following command:
bash -c "chmod +x myexec"
you can use next code, it worked very well for my needs i tested on pwsh version 7 on opensuse.
function Invoke-Sudo {
& /usr/bin/env sudo pwsh -command "& $args"
}
Invoke-Sudo "chmod +x /usr/bin/filename"
I hope this help you!
Executable flag is a linux/unix term.
... on windows it is not relevant.
Stick with the solution you currently have of invoking the bash command from inside the PS script

Sysinternal Close Handle working in Command Prompt But Not Powershell

I have a strange issue. I am trying to close down a handle using Powershell using this 1 liner:
(&"D:\handle.exe" -p "–c C –p 3348 -y")
I am getting the following response:
No matching handles found.
When I run the exact same command in Command Prompt
handle.exe -c C -p 3348 -y
I get:
Handle closed.
I am running Powershell and Command Prompt as Admin.
edit: Note: I can run the same command inside the Powershell Command Window and get the same expected result as I did from the normal Windows Command Prompt.
You don't need any fancy syntax. PowerShell can run command-line programs just like cmd.exe can. Just type the command you want and press Enter.
handle -c C -p 3348 -y
It is likely you need to run this from an elevated PowerShell window, but that's not different from cmd.exe.

How can the terminal in Jupyter automatically run bash instead of sh

I love the terminal feature and works very well for our use case where I would like students to do some work directly from a terminal so they experience that environment. The shell that launches automatically is sh and does not pick up all of my bash defaults. I can type "bash" and everything works perfectly. How can I make "bash" the default?
Jupyter uses the environment variable $SHELL to decide which shell to launch. If you are running jupyter using init then this will be set to dash on Ubuntu systems. My solution is to export SHELL=/bin/bash in the script that launches jupyter.
I have tried the ultimate way of switching system-wide SHELL environment variable by adding the following line to the file /etc/environment:
SHELL=/bin/bash
This works on Ubuntu environment. Every now and then, the SHELL variable always points to /bin/bash instead of /bin/sh in Terminal after a reboot.
Also, setting up CRON job to launch jupyter notebook at system startup triggered the same issue on jupyter notebook's Terminal.
It turns out that I need to include variable setting and sourcing statements for Bash init file like ~/.bashrc in CRON job statement as follows via the command $ crontab -e :
#reboot source /home/USERNAME/.bashrc && \
export SHELL=/bin/bash && \
/SOMEWHERE/jupyter notebook --port=8888
In this way, I can log in the Ubuntu server via a remote web browser (http://server-ip-address:8888/) with opening jupyter notebook's Terminal default to Bash as same as local environment.
You can add this to your jupyter_notebook_config.py
c.NotebookApp.terminado_settings = {'shell_command': ['/bin/bash']}
With Jupyter running on Ubuntu 15.10, the Jupyter shell will default into /bin/sh which is a symlink to /bin/dash.
rm /bin/sh
ln -s /bin/bash /bin/sh
That fix got Jupyter terminal booting into bash for me.

Automation of Cygwin configuration with PowerShell

I have installed Cygwin using PowerShell scripting.
I am doing the following step manually:
Running a new cygwin bash shell (after the edit of cygwin.bat) and enter:
mount --change-cygdrive-prefix /
chmod +r /etc/passwd /etc/group
chmod 755 /var
Start Cygwin bash shell and run ssh-host-config. Answer yes to all the key generation questions.
Is it possible to automate these things in PowerShell scripts, like installing Cygwin, then doing steps 1 and 2 in a single shot?
Use this command:
bash.exe ssh-host-config --yes -u "Cygwinuser" -c "binmode ntsec tty" -w "pwd#123"
cygrunsrv -S sshd
Later go to services.msc to check if the service is running or not

How to RUN plenv/rbenv in Dockerfile?

I want to use plenv to have perl 5.16 in the docker image. apt-get only get 5.14.
plenv will install perl in $HOME/.plenv/versions/5.16.2/, and I need to append some lines into $HOME/.profile:
export PATH="$HOME/.plenv/bin:$PATH"
eval "$(plenv init -)"
Then run plenv shell 5.16.2 to swith to the new version.
But in Dockerfile, I need to write source $HOME/.profile && plenv shell 5.16.2 everyline before I run some perl commands. docker didn't exec $HOME/.profile, is it a no-login shell?
Though I could write such command before every RUN, how can I do this in CMD line?
Do docker can solve this by some setting?
You can use the ENTRYPOINT command to prepend something before each executions or you can simply move your .profile within your .bashrc.
Indeed, docker is a no-login shell, it will not run upstart, simply execute the requested process.