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.
j-ray is right about the missing /, but #!/bin/sh is still incorrect. -a is not an option to exec when using a POSIX shell (sh.) You want to be using bash as the interpreter, if you're going to keep the -a.
jhwilliams is of course correct. I do always find it interesting that what someone says and then when they show the example are often different things.
Quote:
Originally Posted by sagar.gunjal
yes i am using the Bash
Quote:
Originally Posted by sagar.gunjal
#!bin/sh
Apart from the typo these two statements are not the same
Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability.
To be fair, a lot of people don't really understand what the shebang does. They run the script from their bash consoles, but don't realize that that first line in the script is what tells the system which interpreter to use for it. The shell you launch it in doesn't matter when you execute a script directly.
And for the record, the default "/bin/sh" interpreter may actually be bash, depending on how your system is configured. But sh is always treated as a posix-compliant script, and even bash will ignore or error out on most non-posix structures inside such a script.
Of course, you can alternately run a script by directly specifing the interpreter you want as the program name, and pass the script itself to it as an argument. Run this:
Code:
bash scriptname.sh
...and it will be interpreted as a bash script, no matter what the shebang says (since the line starts with #, it's treated as a simple comment).
BTW, The c code likely doesn't work because exec is not a stand-alone program, but a shell built-in. The system function isn't told what interpreter to use for that command.
To be fair, a lot of people don't really understand what the shebang does. They run the script from their bash consoles, but don't realize that that first line in the script is what tells the system which interpreter to use for it.
Especially as there is the default /bin/bash in Linux, hence it even runs with a typo in the first line most likely in the way you expect it.
To the original problem: whether I use #!/bin/sh or #!/bin/bash doesn’t matter, it always accepts -a. I assume the original poster is using Solaris, where the default may be csh. And as a result of the typo the default csh on Solaris is used for the script and throws the error as in csh the option -a isn’t allowed to exec.
I assume the original poster is using Solaris, where the default may be csh. And as a result of the typo the default csh on Solaris is used for the script and throws the error as in csh the option -a isn’t allowed to exec.
I disagree; probably that sh is a symbolic link to the more common dash or busybox; csh has mostly been tossed in the trash by now. To that point: are you kidding me, Solaris defaults to csh?
The first one replaces the shell process with the java process, and the second one causes the shell to wait until the java process finishes, and then continue.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.