Git bash change into a directory and start a file - windows

My default git bash starts on the C: drive and I often have to change into a project directory and start a file up.
Is there a way to cd into a directory and start a file all in one command using Git bash on Windows?

You should have a file .bashrc into your home directory. It should be under
C:\Users\login
Add the following line in the file: cd "projet_directory_full_path"
Open a new session and it should start on your project directory

Yes, you can directly start with cat command following with complete path using forward slashes as 'cat C:/Users/username/filename' and cd command also works in similar way.

Related

Command not found in ssh but is in direcory

I am using an ssh account that connects to an external server, i have downloaded through guix some software like samtools and bedtools but when i try to use them in my directory it gives me this error:
-bash: samtools: command not found
In my direcory, however, there is the directry guix.profile and if I go into the bin folder of this, I have everything I downloaded.
What am I doing wrong?
Thank you
enter image description here
To run a file from the shell you need two things:
The shell must find the file
Being in the same directory does not enable the shell to find the file. You have to either supply an absolute or relative path the file, or have the directory in your PATH environment variable
In simplest terms this means instead of
$ samtools
try
$ ./samtools
The relative path tells the shell it wants that file
To run it from another directory, either use the whole absolute path, e.g. /home/yourname/samtools , or move the file into a directory that is on your $PATH
The file needs to be executable
If the file is not executable you will need
$ chmod +x ./samtools

Why ubuntu terminal unable to find file or directory?

I'm using Ubuntu 20.4.05 LTS. It is not locating any directory as you can see in the image. For example, cd ~/Downloads doesn't take me to the directory.No such file or directory image What should I do?
as a first step you must know the position of the directory by writing the command pwd
pwd
then you can write the ls command to see the contents of the list of folders or directories
ls
if the file you need is in that directory, you can enter that file by writing the command cd
cd
access folder

Change directory in bash script in windows

How can I change my working directory in bash script in windows. I have
~dp0 = C:\test\docker\windows and I want to change my directory to C:\test\build
So it means 2 levels up and then int o build folder
Thanks
Since C:\ is mounted by default into /mnt/c this will work.
Create a .bashrc in your home path by following command:
echo "BUILDDIR=/mnt/c/test/build" >> ~/.bashrc;source ~/.bashrc
cd $BUILDDIR
# Do your work below for example ./configure.
./configure
On my system in Git bash the C:\ root is just /c/ and other dirs from there are whatever they are, so it would be cd /c/test/build/.
You could also still say cd ../../build/.
Good luck.
To change the directory using a bash script is just like you would using normal bash.
cd "C:/test/build"
echo "You're now in the folder, do what you will."
Save the file as .sh and it can be used as such.
Note, when navigation your folders using a bash script remember the directory you'll be starting from is always the home directory.

cd commands not working from .bash_profile on MobaXTerm

I'm on Windows 10, using MobaXterm. I have a persistent home directory, and I've created .bash_profile there. My .bash_profile contains:
echo "Loading bash profile."
cd "/drives"
When I open a new MobaXterm tab, I get:
Loading bash profile
: No such file or directory
But when I run:
cd "/drives"
from the command line, it changes directory to /drives.
I don't really need to go to /drives when a tab starts up, what I want to do is create alias for cd commands that go to long directory names without having to type them out every time, but no cd commands will work from .bash_profile, I always get 'No such file or directory'. Any ideas?
I contacted MobaXTerm support, and their reply was to convert the .bash_profile to unix format with this command:
dos2unix /home/mobaxterm/.bash_profile
Now the cd commands work as expected.

Using Leiningen in Git Bash on Windows

So i installed Leiningen and git on windows. But git bash does not seem to find the lein command because it is based on a .bat file. It works in the windows command line. Is there any way to get the lein command to work in git bash?
First, I added the lein.sh script into ~/bin folder. This folder should be added in the path by GitBash itself. If it's not in PATH, you can add lein.sh to any folder that is in there or simply add ~/bin to your PATH. Something like:
PATH=$PATH:~/bin
You can set the following alias on "~/.bashrc" in your home directory to it easier to call Leiningen:
alias lein='lein.bat'
It's working fine with Leiningen 2.6.1 and Git Bash 2.8.0.
If I go into git bash and type echo $PATH I see what seems like the same thing as when I type echo %PATH% from a dos console.
So I alter the Windows Path environment variable so it includes C:\programs\lein, which is where lein.bat is.
Back into git bash I type lein and get command not found. But if I type lein.bat I can see it is trying to run the file, presumably as if it were a shell script:
Chris#CHRIS-XPS ~
$ lein.bat
/c/programs/lein/lein.bat: line 1: #echo: command not found
/c/programs/lein/lein.bat: line 3: setLocal: command not found
/c/programs/lein/lein.bat: line 7: syntax error near unexpected token `('
/c/programs/lein/lein.bat: line 7: `if "%LEIN_VERSION:~-9%" == "-SNAPSHOT" ('
So you will be able to get further by dropping in lein.sh to replace lein.bat. Good to start with your own lein.sh that tries to only execute java -jar lein.jar -cp ... (I made that up but it should be possible to piece the correct command together from viewing the batch file (or the shell script)). In fact if your Windows hosted lein.sh can start any java program, it should also be able to start lein.

Resources