What's new

same variable name in different bash scripts

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

slytho

Regular Contributor
Hi!

I have two different bash scripts. They perform independent tasks from each other, but can possibly run at the same time (during boot process). In both sripts there are variables (for instance to count loops). Can it cause confusion if both scripts use a varibale with the same name or does the system cater for separation between both scripts?
 
Bash scripts work completely independently. They run within their own processes. Things like variables, constants, functions, etc., are normally only local in scope. IOW, they can NOT conflict w/ other scripts running in other processes. Of course, you can run into conflicts when those scripts try to access resources *outside* their own processes that they share in common (e.g., a file in the local filesystem).
 
Assuming each script is run separately (i.e. one script does not invoke the other) then the variables are local to each script.

This is true for other shell languages like sh not just bash. Asus routers for example don't support bash scripts but do support busybox's version of sh.
 
Ahh, great. Good to know that. I wasn't sure how it works. And no, these scripts don't access resources outside of their own processes. Thank you very much for your prompt answers. :)
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!

Staff online

Top