This question already has an answer here:
Why would a correct shell script give a wrapped/truncated/corrupted error message? [duplicate]
(1 answer)
Closed 6 years ago.
I've made a simple bat file "run_perl.bat" that executes a Perl script "Oncomine_main.pl" in \data\test_scripts directory.
Here is the content of the bat file:
cd /data/test_scripts
perl Oncomine_main.pl
I run the script from the login directory
Here is what is returned to me:
[username#path-twood3 ~]$ ./run_perl.bat
: No such file or directory /data/test_scripts
": No such file or directorymine_main.pl
Please suggest how to fix this issue?
Thank you
Add #!/bin/sh as the first line of run_perl.bat.
Related
This question already has answers here:
How can I run a function from a script in command line?
(10 answers)
Closed 1 year ago.
I have a code in a file named main.sh:
#!/bin/bash
function hello() {
echo $1
}
I want to call it from command line like this:
main hello teddy
and it should output like hello teddy.
Is that possible?. If yes, Please tell me.
Thank you in advance
It is possible depending on where you define the function. There are several bash startup files which are run on startup. For example, .bashrc:
When an interactive shell that is not a login shell is started, Bash reads and executes commands from ~/.bashrc, if that file exists.
So if you define your function in your .bashrc you will be able to run it just as if you had explicitly defined it using the shell.
This question already has answers here:
./configure : /bin/sh^M : bad interpreter [duplicate]
(15 answers)
Closed 4 years ago.
I create start.sh file and wont to start,but retruned me
./start.sh: /bin/bash^M: bad interpreter: No such file or directory
this is my start.sh file content
#!/bin/bash
cd /home/test/Desktop
node cron.js
How can I fixed this problem?
It means your script file has MSWin line endings. Use dos2unix or fromdos to fix them.
This question already has answers here:
How do you normalize a file path in Bash?
(24 answers)
Closed 6 years ago.
I've a shell script at
/home/abc/xyz/test.sh
I've a file at
/home/def/ghi/jkl/lmn/foo.txt
I'm running the scrip from /home as I've set my PATH variable to point to /home/abc/xyz/
I'm passing the relative path of foo.txt to my script like so test ./def/ghi/jkl/lmn/foo.txt
I want to capture the full path of foo.txt into a variable in my script, any pointers?
Tried https://stackoverflow.com/a/5265775 and https://stackoverflow.com/a/9107028/4468505 but in vain.
foobar=`readlink -f <passed in relative path to foo.txt>`
This question already has answers here:
How can I cd into a directory using a script?
(4 answers)
Closed 7 years ago.
My script
#!/bin/bash
for file in *.ats; do
mv $file /home/holmes/procmt
done
cd /home/holmes/procmt
All files are moved but I want to change my current directory to /home/holmes/procmt and nothing happens.WHY?
If i run script ./pch.sh,I stay in the same shell.
The shell running the script moved, but the shell you were typing in when you started the script stayed put. If you precede the name of your shell script with . (dot space) it will run in 'your' shell.
This question already has an answer here:
Why is a shell script giving syntax errors when the same code works elsewhere? [duplicate]
(1 answer)
Closed 7 years ago.
I seem to be having a weird problem, the solution for which might be dead simple and I am just being blind.
My development environment is Windows. I create a deployment archive file, within which contains a shell script file (called install.sh). I sftp this archive over to a linux environment, untar it and try to run execute the script (after chmod to make it executable) and I get this error:
syntax error: unexpected end of file
I don't notice any errors in the file. I delete this file, create a new install.sh, copy over the exact contents from my Windows env, chmod it again, run it again and this time it runs fine!
I have no idea why it does not run the first time I untar it. Any help appreciated!
Check your file:
cat --show-nonprinting file
Remove carriage returns from Windows/DOS:
tr -d "\r" < file > fixed_file
Linux and Windows uses different end of line (CL or CLRF), or maybe it's an encoding problem. You should check the differences between the running sh and the non-running one.