How to open a wsl directory in git bash terminal - linux

I want to open this \\wsl.localhost\Ubuntu wsl directory in git bash terminal. My git bash terminal is currently open in /c/Users/DELL directory.
I tried \\wsl.localhost\Ubuntu pasting this command in the bash shell, but it throws error saying that bash: \wsl.localhostUbuntu: No such file or directory .
Can anybody help me opening that in git bash terminal.
Few days back i managed it to open that in git bash, see this image
But now I am unable to do so, don't know how I managed to do so earlier

Run this command:
cd //wsl.localhost/Ubuntu
The command \\wsl.localhost\Ubuntu didn't work, because
Bash removes backslashes while parsing the command (solution: use forward slashes: /).
You didn't indicate that your want to change the current directory, without that Bash interpreted your command as running an external program by that name (solution: use the cd command).

Related

How to open a specific directory by default on start up of Command line?

When I start up command line, I want a specific directory to be opened by default without me having to type a long path.
e.g.
every time I open a terminal I want to be in directory ~/Desktop/foo/bar, so I want the following to happen
ctrl+alt+t
-> "terminal opens"
pwd
-> <yourPath>/Desktop/foo/bar
You can put this line at the end of your ~/.bashrc file (or equivalent if you're using a different shell than bash):
cd <yourPath>/Desktop/foo/bar
Just add a command to the end of your .bashrc
cd /path/to/dir
If it's Ubuntu terminal you can edit your profile, tick run a custom command instead of my shell and make it:
sh -c 'cd ~/Documents; exec "${SHELL:-sh}"'
What you might also consider if you want to move through directories quickly as bookmarks (almost), check out zsh which has a plugin called warp directory or if you don't want to make the leap to zsh, warp-drive fork.

bash: ./shelllab2.sh: No such file or directory

I am running shell scripting program using git bash on windows 10.
I am sure I had created my file here then also getting this error.
bash: ./shelllab2.sh: No such file or directory
Check first where you are when you try to access that script:
pwd
ls -alrth
You will see if ./shelllab2.sh is indeed here.

bash changing directory when started

I have both Bash on Ubuntu on Windows and Cygwin bash installed on my machine, and both are setup to have the same ~ folder (via /mnt/c/source and /cygdrive/c/source respectively).
When I start Ubuntu's bash prompt via bash --login -i (or just bash --login) from any directory, I get a prompt running from within that directory; however, when I start Cygwin's bash via the same command, the current directory is overridden, and the prompt is always at ~. See the screenshots for a simple example.
My user directory's .bashrc and .bash_profile are of course the same, as both are using the same user directory. I've looked into Cygwin's /etc/bash.bashrc and there doesn't seem to be anything there to change my current directory, and there aren't any other relevant files in /etc.
What could be causing Cygwin's bash to change directory?
you just add a command "cd /dir_you_want" at the bottom of ~/.bashrc in cygwin
I've figured it out, so in case anyone runs into the same issue:
There's one file I neglected to look into, because I didn't know it exists, /etc/profile. In Cygwin, by default it has the following section in it:
# Make sure we start in home unless invoked by CHERE
if [ ! -z "${CHERE_INVOKING}" ]; then
unset CHERE_INVOKING
else
cd "${HOME}" || echo "WARNING: Failed attempt to cd into ${HOME}!"
fi
Disabling that solves the issue of course.

"cannot execute binary file" when trying to run a shell script on linux

I am very new to linux and shell scriprting.
I am trying to run a shellscript from secure shell (ssh) on linux using following commands:
chmod +x path/to/mynewshell.sh
sh path/to/mynewshell.sh
I get this error:
path/to/mynewshell.sh: path/to/mynewshell.sh: cannot execute binary file.
Tried using this command:
bash path/to/mynewshell.sh
I get the same error.
Tried with this command: su - myusername sh path/to/mynewshell.sh
It is asking for my password and giving me this error: no such file or directory.
1.The result of cat -v path/to/mynewshell.sh is:
^#^#^#^#^#^#^#^#Rscript "$dir"/diver_script.R
done
2.When tried 'less path/to/mynewshell.sh' i got this on my terminal:
#!/bin/bash/Rscript^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#
^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#
for dir in /path/to/* ; do
^#^#^#^#^#^#^#^#Rscript "$dir"/myRscript.R
done
3.When i ran file path/to/mynewshell.sh : i got this "Bourne-Again shell script text executable"
Please give any advice on how I can try executing the shellscript.
chmod -x removes execution permission from a file. Do this:
chmod +x path/to/mynewshell.sh
And run it with
/path/to/mynewshell.sh
As the error report says, you script is not actually a script, it's a binary file.
I was getting the same error running my shell script through a bash interpreter in PowerShell. I ran dos2unix myscript.sh on the shell script, and now it runs ok.
From a proposed duplicate:
run_me.sh.xz: run_me.sh.xz: cannot execute binary file
This is because the file is compressed, as indicated by the .xz extension. You need to remove the compression before the file can be used.
xz -d ./run_me.sh.xz
chmod +x ./run_me.sh # probably not necessary if you already did that before
./run_me.sh
Other compression schemes like gzip (.gz extension), bzip2 (.bz2 extension) etc behave similarly; you just have to know the name of the command to uncompress it, which is of course usually easy to google.
To anyone else having the problem i had.
i was trying to run a 16 bit unicode text file converted to a shell script, this doesn't work as all 16 bit unicode text files have a 0xFFFE marker at the start making mac os not like the file and this gives the “cannot execute binary file” error.
open the text file click on "Format" at the top, go down to "Make Plain Text" click it.
open your terminal type chmod 777 /path/to/file.sh
put in terminal: /path/to/file.sh to run it
That script is simply not a shell script.
A shell script is usually readable and contains shell code.
The output your cat command shows looks indeed like it's a binary of some sort.
As some note, it might be because of a file conversion issue when copying but it looks more like an actual binary to me.
You can check what it is identified as with the file command so:
file path/to/mynewshell.sh
Just start with a clean script and rewrite the code, it looks like you just want to run some R scripts in a directory?
Make sure the R scripts point to the right R script executioner.
In my case I had a bash script that would not execute. The file was originally generated from a find ... -print0 command. Leaving a \0 character the script, removing that character solved my problem.

run a command on the remote machine after ssh login

I would like to switch to the bash environment after ssh login. Currently I have to type bash every time and then cd to my working directory.
Where can I add some settings so it will run automatically for me.
There's an environment variable SHELL that is set to the current shell. You can set it to your preferred shell by running
$ export SHELL=/path/to/shell
In order to find the path to your preferred shell just run following command
$ whereis bash
Enter the path returned by whereis command as your shell path.
There's a .profile(ls -al) or bash_profile that you can add your setting there. If you can't find such a file then create one using touch .profile. (I did create this file on OS X.)
Open the .profile in order to edit it using whatever text editors that you want
$ vim .profile
Then change the $HOME environment variable in order to change your default home directory path. Enter below line in opened file
export HOME=/your/path
Save the file
:w

Resources