Problem in Bash Scripting

In Learn the Command Line Course on codecademy, it was provided how to configure our personal bash environment so we can access a file from anywhere by typing the filename.
The configuration was:
PATH=~/bin:$PATH

When I used this configuration on my system it didn’t happened that way.

User@User-PC MINGW64 /
$ cd

User@User-PC MINGW64 ~
$ export PATH=~/bin:$PATH

User@User-PC MINGW64 ~
$ script.sh
bash: script.sh: command not found

User@User-PC MINGW64 ~
$ ./script.sh
bash: ./script.sh: No such file or directory

I used the file name as script.sh and also included #!/bin/bash at the start of the file and chmod +x script.sh at the end of the file.

The link to the respective page of the course is: https://www.codecademy.com/courses/learn-the-command-line/lessons/learn-bash-scripting/exercises/introduction

Please Help.

1 Like

and script.sh is placed in bin? You could do:

echo $PATH

to verify the path is correctly added.

It didn’t worked out @stetim94 .
What happened now is:


User@User-PC MINGW64 /
$ cd

User@User-PC MINGW64 ~
$ export PATH=~/bin:$PATH

User@User-PC MINGW64 ~
$ echo $PATH
/c/Users/User/bin:/c/Users/User/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/User/bin:/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/cmd:/c/MinGW/bin:/c/Program Files/JetBrains/PyCharm Community Edition 2019.3.2/bin:/usr/bin/vendor_perl:/usr/bin/core_perl

User@User-PC MINGW64 ~
$ ./script.sh
bash: ./script.sh: No such file or directory

User@User-PC MINGW64 ~
$

I can see that the path has been added but still it didn’t work out. If you can tell me something else which could be useful, that would be great.

super weird. Are you using cygwin? If using windows 10, i would recommend using WLS (windows linux subsystem)

Haven’t used cygwin in ages? Can i see the output of the following commands:

pwd
ls -l ~/bin

using ./ will execute from current directory, not PATH.

You could navigate to the bin directory:

cd ~/bin

then try:

./script.sh

see if that works