ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi Ive just moved over to Linux from Windows and I am trying to convert a Windows batch file to a unix shell script to run a java application, but it so long since Ive used UNIX I cant really remember how to do it.
My script contains
#!/bin/sh
java -jar lib/testapp.jar
These are my failed attempts to run it, not too sure what the differences are but I think the 3rd one is the only one to actually find my shell script.
[root@]# testapp.sh
-bash: testapp.sh: command not found
[root@]# ./ testapp.sh
: bad interpreter: No such file or directory
[root@]# . testapp.sh
Unable to access jarfile lib/testapp.jar
if I just do this at the command line it works fine
Thankyou, od -c has cracked the problem i have \r at the end.
I recreated the file from scratch and it is now runs ok (im suprised it causes such a problem though)
As for bin/sh the file does exist but is actually a symbolic link to /bin/bash the script seems to run ok without the line at all. So is there any reason to have this line
Distribution: Solaris 11.4, Oracle Linux, Mint, Ubuntu/WSL
Posts: 9,788
Rep:
You shouldn't be surprised, the end of line character (\n) under unix is the single line-feed character, and not the double carriage-return/line-feed like DOS/Windows.
Moreover, CR (\r) is a valid filename character for most unix supported file-systems, so it isn't forbidden, although not a smart idea, to have one interpreter named /bin/sh and another one named /bin/sh\r , and the #! construction should be able to distinguish between them.
About the bash question, it is probably a good idea to leave /bin/sh instead of /bin/bash, as it makes your script more portable, unless you use bash specifics unsupported on the real bourne shell.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.