I'm trying to execute test.sh on terminal.
My test.sh is in the /Home/monty folder and I made it executable:
chmod 755 test.sh
I try to execute it using:
$./test.sh
I get an error:
bash: ./test.sh: /usr/bin/bash: bad interpreter: No such file or directory
I tried to do this on terminal:
$ PATH=$PATH:/Home/monty
But to no avail.
How do I solve this issue?
I solved the problem by changing the end of the line from CRLF to LF since my script was edited in windows.
You probably have set the wrong shabang. In ubuntu bash is normally located in /bin/bash so at the top of the file you should have:
#!/bin/bash
instead of:
#!/usr/bin/bash
Another way to run the script is to just tell bash (or sh) to execute it:
bash ./test.sh
In my case, I did sh file.sh, which was definately there, but in the file I had cp /other/file.sh and the other file was missing. Yet the error message only said sh file.sh: Not found.
Related
I'm working on an Ubuntu 18.04 and I'm trying to run a very simple bash script named print_test:
#!/bin/bash
echo 123
I have the $PATH variable set correctly (it includes the /bin directory) and I have tested that
I'm using the correct line ending (wc -l print_test results in 2). I have changed the permissions using
chmod +x print_test. When I try to run the script I get:
print_test: command not found
Any idea what I might be doing wrong?
Note: when I simply run echo 123 in the terminal it does prints 123 .
Thanks!
If the path is set properly it must work
Easier way , to invoke a shell script
chmod +x script.sh
./script.sh
Here replace script with the name of your script
Use this at the first line of your script
#!<path/to/bash>
I'm trying to run a CLI tool in Linux (Mint) which allows me to edit subtitles. It is named subedit: github link. In order to run it, I've added executable permission with chmod +x and added it to the path in bash. However, when I run it, I get the following error message:
bash: /home/main/Documents/shellTools/subedit/subedit: /usr/bin/bash: bad interpreter: No such file or directory
I'm not very experienced with external bash programs and forgot to do something that would be obvious in hindsight.
When I do echo $PATH this is the output:
/home/main/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/main/Documents/shellTools/subedit/
Could somebody please help?
Assuming bash is installed, (it usually is), change the first line of subedit from:
#!/usr/bin/bash
to:
#!/bin/bash
Or if one would prefer not to edit subedit, try this one-liner covering what Al-waleed Shihadeh suggested:
ln -s "$(which bash)" /usr/bin/bash
It seems that you don't have bash installed, you can verify that by running
which bash
if the above command returns "bash not found", then you need to install it.
In case the above command returns a path, you can use the below command to add a symlink to the expected path
ln -s $(path from the above command) /usr/bin/bash
Use the command termux-chroot ONCE!
If you want to always run at the start of a session, be sure to check if it was never run before.
if [ -z $CHROOT ]; then
CHROOT=1
termux-chroot
fi
I've written a simple script, that basically looks like this:
#!/bin/bash
echo Hello World
I'm trying to run this in my unix terminal but it basically does nothing. no errors, no printing, nothing
[solgag#t2 ~]$ olga
[solgag#t2 ~]$
any ideas?
Try ./test instead. If you run just test, bash will look for an executable named test in $PATH and it will find it (or maybe execute its own built-in?) as test is a standard command in UNIX.
if you shell script name is olga you need to run in terminal as
$./olga
To run the script as specified above you need to have executable permissions you can add executable permission using chmod command
$chmod u+x ./olga
You can also run a bash script using sh command
$sh olga
In the following script (saved as script.sh):
#!/bin/sh
cd $MY_PYTHON_WORKING_DIRECTORY
python script1.py
python script2.py
Then, when I try to run the command script.sh in my bash shell, I got the error bash: script.sh: command not found. Why does this not work as expected? If the first line of any scripts start by #! prefix, then the following path on the line is interpreted as a command, right? For your information, even if I changed my first line to #!/bin/bash, the same error still occurred. If I run the script as either sh script.sh or bash script.sh, then the script ran as expected.
Is there any way to run the script by just hitting script.sh?
One more question, between sh and bash, which should I use? I'm on OS X 10.8 and my default shell is currently set bash, but I wonder which one to use going forward.
Thanks.
First, make the script executable:
chmod u+x script.sh
Second, your current directory is not in your $PATH. Therefore, you have to run the script with a path (relative is enough):
./script.sh
I've just begun learning Unix and have so far encountered two elementary though difficult to resolve problems:
When I set HOME='' in a shell script to a designated directory, the current directory no longer seems to be recognized. That is, 'cd ~/' spits out the message: 'no such file or directory' message. Although, curiously enough, if aliases assignments are made within the script, a source call seems to activated them nonetheless. How come?
Ex:
$ more .profile
HOME="~/Documents/Basics/Unix/Unix_and_Perl_course"
cd $HOME
[...]
$ source .profile
-bash: cd: ~/Documents/Basics/Unix/Unix_and_Perl_course: No such file or directory
When I created a simple shell script via nano ('hello.sh'), I can't seem to execute it simply by typing 'hello.sh' in the terminal. This issue fails to resolve even after I 'chmod +x' the file. What's the problem?
Ex:
$ more hello.sh
# my first Unix shell script
echo "Hello World"
$ hello.sh
bash: hello.sh: command not found
Thanks!
You also don't want to 'overload' $HOME, the default location for HOME is always your home directory. If you goof with that, lots of things will break.
As far as hello.sh - thats because you don't have '.' in your $PATH. (Which is a good thing)
Try:
./hello.sh
If it says it can't execute
chmod 755 hello.sh
./hello.sh
~ = $HOME
. (pwd) is not in $PATH