[SOLVED] Calling a Shell script from inside a Shell script
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.
sh -x delete_correspondence.sh
+ sh $'test.env\r'
: No such file or directory
\r indicates a carriage return; windows/dos uses \r\n to indicate end of line, but unix uses only \n. You can convert to unix line endings with unix2dos (aka u2d), or with any decent text editor.
As the purpose is to set environment variables, it’s necessary to source the test.env instead of executing it. Otherwise they are set in subshell only and vanish on return. Either of:
No, shebang or "it" was never confused, the OS (or shell) always knows what to do and how to do. I think you are confused because you do not know what happened.
when you explicitly defines the shell (so executes: <interpeter> <scriptname>) the shebang has no effect - or maybe the flags of the shebang has some influence in some cases. So sh delete_correspondence.sh will use sh and it does not work, bash delete_correspondence.sh works.
When you execute the script itself without defining the interpreter the shebang interpreter will be executed (if exist) instead of the script and that interpreter will process the script. So using #!/bin/sh will execute sh delete_correspondence.sh again which fails. Without shebang the current interpreter/shell will be invoked to process the script. Finally, in your last example (using source or . ): . delete_correspondence.sh the current actual shell will process the script without invoking any other shell therefore the shebang has no meaning in this case again.
The root cause of your problem is probably the \r which was already mentioned, you need to remove it. bash could handle it (silently ignored), but sh assumed this is still part of the filename and could not find the file. Probably you edited this file under windows?
The root cause of your problem is probably the \r which was already mentioned, you need to remove it. bash could handle it (silently ignored), but sh assumed this is still part of the filename and could not find the file. Probably you edited this file under windows?
It was edited using a windows x-windows client, which must add the \r.
I made the changes on a different box, using Putty, which would explain why it works.
It was edited using a windows x-windows client, which must add the \r.
I assume you mean “using a windows x-windows server” and started a client application on the Linux machine. Which graphical application did you use? I assume that using x-windows would hide the platform dependent behavior.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.