Korn Shell path not found - linux

I have a problem with a script ksh (mainScript) that call other scripts.
mainScript:
call ./folder1/folder2/first.sh
error that I get:
./folder1/folder2/first.sh not found [No such file or directory]
I verify with ls -l /folder1/folder2/first.sh and I see that the script exist.
Thank you for helping me.

remove the . from your path and also provide execute permission on the file then you will be able to run the script. like
[root#localhost#] chmod +x /folder1/folder2/first.sh
then run
[root#localhost#] /folder1/folder2/first.sh
Also, you can run your script using following:
ksh /folder1/folder2/first.sh or sh /folder1/folder2/first.sh or bash /folder1/folder2/first.sh etc

Related

./ Dot Slash not working to execute Shell Scripts

I'm definitely a command line novice. I have recently lost the ability to execute shell scripts using
./script.sh
I am still able to execute shell scripts using:
sh script.sh
My $PATH is as follows:
/Users/goodguy/.pyenv/shims:/Users/goodguy/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/local/sbin:/Users/goodguy/.rvm/bin
I am using MacOS. I'd appreciate any insight into what I may be doing wrong
you can run command chmod 755 script.sh
and then run the script with ./script.sh

exec command in bash doesn't work when calling a shell script

The following are two shell scripts stored in the same folder with execute permissions on both:
shell1.sh
#!/bin/bash
exec shell2.sh
shell2.sh
#!/bin/bash
pwd
When trying to execute shell1.sh I am getting the following error:
./shell1.sh: line 3: exec: shell2.sh: not found
Is there something I am doing incorrectly? This works in other machines though but just in one particular server its not working.
Any suggestions would be helpful.
The current dir is not part of your PATH.
Try
exec ./shell2.sh

Shell script file (.sh) does not run, and throws an error

I am new to linux, and I have a shell script (.sh) file on my Desktop that I want to run.
These are the steps that I did:
This is the content of the test.sh file on my Desktop:
#!bin/bash
#test.sh
echo "test"
I want to run (Execute) test.sh through the terminal. These are the commands that I'm using:
cd Desktop
I give permission to run test.sh with:
chmod +x test.sh
and then try to open the file:
test.sh
But I get this error:
test.sh: command not found
What am I doing wrong?
Your shell will search the directories in your $PATH environment variable for executable files.
If the current directory is not in it (and your Desktop directory won't be, by default), you must specify the path explicitly.
./test.sh
bash: ./test.sh: bin/bash: bad interpreter: No such file or directory
Replace:
#!bin/bash
With:
#!/bin/bash
Source
try running the script like this: ./test.sh
Do like this:
FIRST WAY:
bash test.sh
or
sh test.sh

bad interpreter: Permission denied in shell scripting ls ubuntu

I am quite new to the shell scripting.
So I am writing the shell script to list all files available in the directory using ls command.
but I am getting the error bad interpreter: Permission denied
#!/home/gaurav
echo "Welcome bash shell scripting"
ls
echo "this complets the listing of directories"
I want to get the list of "/home/gaurav" this path
Thanks
This line...
#!/home/gaurav
... means "instead of using /bin/bash, use /home/guarav as the program to run this file". This is not what you want. What you want is either:
cd /home/gaurav # at the top, or
ls /home/gaurav # between echoes
Problem is this line:
#!/home/gaurav
This is called shebang and it should be the bash/shell interpreter like this:
#!/bin/bash
one that interprets and executes your script. Since /home/gaurav is not a valid interpreter you're getting that error.
You probably want this in your script:
ls /home/gaurav
to list all files/directories in /home/gaurav path.
Either add #!/bin/bash or #!/bin/sh instead of #!/home/gaurav line while starting script.
Because, while running shell script, you have to give path of which bash or sh are you going to run to execute that script.

run linux command succeed but failed in .sh file. "No such file or directory "

I wrote a linux command and it runs perfectly in command line:
/bin/netstat -an | grep '3306' | sed 's/.*/[MYSQLMON]&/' > /home/bbWifiExt/logs/WIFIMonitor.log
however when I copy this code to .sh and run the .sh file i got:
No such file or directory
Can anyone tell me why? Many thanks.
You must either call it as
sh mycommand.sh
or make your shell script executable. Insert #! /bin/sh or #! /bin/bash as the first line and
chmod +x mycommand.sh
before calling
mycommand.sh
for my situation (rename and copied file from windows to linux) the solution was :
dos2unix script.sh
If the first line of the script something like
#!/bin/sh
and the execute bit set i.e.
chmod +x script.sh

Resources