I wanted to know what the scope of a "set" command would be in a shell script. Is it limited to the script itself? Or if run via an interactive shell, limited to that particular instance?
Specifically, I'm trying to disable globbing, execute some commands and enable it again
#Disable Globbing
set -o noglob
#Run some cmd's
#Enable Globbing again
set +o noglob
So let's say if someone else logged in on the server and tried to do something while my script is running, will they be affected by the "noglob" that is disabled temporarily?
PS: I do understand the best practices of Quoting variables, but would still like to know the impact of setting noglob.
Thanks
Although the shell is an application, like Firefox or Libre Office Writer, and
set -o noglobis a kind of setting, it's not handled the same way. Theset -o noglobsetting is not stored into a configuration profile of the application; it is only a volatile run-time change which affects that running instance of the shell.Permanent configuration changes to the behavior of a shell have to be manually recorded in a startup script. For instance, GNU Bash, when running interactively, will read a file called
.bashrcin your home directory. If you putset -o noglobin that file, then you will have that setting in effect in every new Bash instance. Other users won't be affected because when they run Bash, it reads their own.bashrc.There are global files in
/etcwhere you could make changes that affect all users. To edit those you need superuser privilege.Applications like web browsers and word processors do this for you; when you change something in their preferences, they make that setting go "live" in that instance of the program and they record it into some configuration file or database, so that it will be in effect if the program is restarted.