Reputation: 385
I'm making a series of bash scripts to remove to nuisance from manually typing out navigation commands into my cygwin terminal. He's one that navigates to my xampp /www/ directory:
#!/bin/bash
cd /cygdrive/c/xampp/htdocs/www
When I run it with the following command:
$ ./www.bat
I get the following error:
C:\Users\user>cd /cygdrive/c/xampp/htdocs/www
The system cannot find the path specified.
What's strange is that when I type that command out manually it navigates to the intended directory without issue. My first thought is that it's an issue with Cygwin's disk drive naming, but if that was an issue it would fail upon manual typing.
What gives?
Upvotes: 0
Views: 1297
Reputation: 2930
The error you're getting is from the windows command line interpreter. It gets called because your script has the .bat
extension. It should be called www.sh
instead.
However, you can't do what you want with a script: a new process would be spawned to run your script, the new process would cd to your directory but at the end of the script the process would end and you'd be returned to the calling shell's process which would have the old current directory. You would need to source the script from bash (. /path/to/www.sh
) so that it would run in the same process as the calling shell, but that would be overkill for what you want. Just add this to your .bashrc
in your home directory (/home/<user>/.bashrc
):
alias www='cd /cygdrive/c/xampp/htdocs/www'
Upvotes: 3