Sign in to post your reply or Sign up for a free account. Sign in Join Now. New Post. I have one configuration file. It will be used by perl and shell script. From perl using 'require' I have included the configuration file. Using require, include statement I tried in shell script , but it was not working.
How to include a file and read value from that file using shell script? Follow Post Reply. Using 'source' we can acheive teh including of files in shell script.
Your probably wondering why I moved your posting. We used to read and then a variable that stores the current character. We output the character using echo. But the argument we have passed in to read i. If you want to go by more characters we can increment the -n to any desirable number. Skip to content. Change Language. Related Articles. Table of Contents. Rob Wells Rob Wells Ouch — l0b0. Exactly one of the three eval blocks near the bottom is always run. So whether it's needed or not, it sure is using eval.
That eval call is safe and it's not used if you have Bash 4. I see, you are one of those old-time scripters who think eval is pure evil, and doesn't know how to make good use of it instead. I don't know what you mean by "not used", but it is run. And after some years of shell scripting as part of my job, yes, I'm more convinced than ever that eval is evil.
Two portable, simple ways to flag files come to mind instantly: Either referring to them by their inode number, or by putting NUL-separated paths into a file. Show 4 more comments. PSkocik PSkocik Xaqron Xaqron Does this also solve the problem of executing the script outside of the dir it is in? It is a structured way for including dependencies in large projects.
An approach like Incorrect quoting, unnecessary use of echo , and incorrect use of sed 's g option. There is bash-helper lib for including libs in that way:! Alexander Yancharuk Alexander Yancharuk After that, one only needs to do this to include files in the same directory:. Joaommp Joaommp 57 8 8 bronze badges.
Django Django 31 1 1 bronze badge. You assume that you are in the same directory where scripts are located. It won't work if you are somewhere else. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.
Email Required, but never shown. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Visit chat. Linked 1. See more linked questions. Related Hot Network Questions. The source command is just an alias for the dot operator in bash.
Both will pretty much work the same in a bash shell context. There is yet another option to execute or call another script.
You can use the exec command to execute the script. This works slightly different than the previous commands. I mostly try to stay away from it, because I have had some bad experiences with it.
The exec will kill or terminate the current shell before executing the called script. So, you will end up with the context of the called script rather than the caller script when the script ends. In most cases, it is fine and work just as well. It is not advisable if there are more commands to be executed in parent script after the called script finishes.
0コメント