Mailinglist Archive: opensuse (818 mails)

< Previous Next >
Re: [opensuse] different types of shell scripts
jdd said the following on 09/22/2011 04:39 AM:
Le 22/09/2011 10:11, George OLson a écrit :

So my question is, what is the difference between running a script
file with the command

<dot><space><filename>, for example "#> ."

"help ."

.: . filename [arguments]
Execute commands from a file in the current shell.

This is normally called 'sourcing'.
On the whole it is NOT a sensible practice for _executing_ a script.
It use is normally to set parameters.

For example, you will see in /etc/init.d/ files that are part of the RC, that are linked into /etc/rc3.d and /etc/rc5.d and so on.

In these files you will see lines such as:

. /etc/rc.status
. /etc/sysconfig/sound
. /etc/sysconfig/boot

This 'execute' the setting of shell/environment variables.
This is a healthy/"Good Practice" use of 'sourcing'.
Its not the only one.

Your .profile and the base and X11 equivalents do a similar thing and they may also actually execute external programs, set things running in the background (such as ssh-agent).

What they are not doing, and what I would consider BAD PRACTICE is running in the current shell things that should be run in a sub-shell or sub-process.

Back when, UNIX started something radically different that we now consider the norm. Back when, processes were deemed expensive to create so they weren't. The CLI just ran one program at a time, had not control flow. There was a "Transient Program Area" and the CLI caused the executive to overlay the CLI with the application. Great for what were single process systems like CPM/DOS and their mainframe predecessors. When the application terminated the system somehow reloaded the CLI and you were off again.

What made UNIX radical was that the CLI, the shell, stuck around; process creation was cheap an easy and so the application was run in a sub-process. That meant the CLI could do things that weren't possible before. It could run a sequence of programs; it could run two (or more) child processes that were connected via pipe.

We take this for granted now, but back in the 70s and 80s this was radical. many people who had grown up with mainframe and mini OSes simply could not get their head around this. The idea of the CLI as a programming language was beyond them.

I am not joking.

I saw this persist into the 1980s. I worked at an establishment where I put up "Software Tools" on the VAX/VMS that I was using (UGH! FORTRAN!) and things really moved. My peers and managers didn't understand what the fuss was and in the end did not appreciate that I was (at least) 5 times as productive because I had suitable tools.

Realistically, its not just having the tools; they were there on the VAX for anyone to use. It is knowing how to use them and use them appropriately. I did; the people who saw VAX/VMS and the CLI and TPA model, processes being 'expensive' so run everything in the one 'shell', couldn't alter their thinking to the 'tools' and throwaway process ("grep for something....", "use sed to transform a file") mode of thinking. Not so much dinosaurs as snails.

You can see examples of appropriate use in the various shell scripts on the system.
Back when, the PDP-11 days, version 6, 7, PDP-11s, small address spaces, small disks, script were used a LOT more than they are today. Pretty much out of necessity.

Leadership is understanding people and involving them to help you do a job. That takes all of the good characteristics, like integrity, dedication of purpose, selflessness, knowledge, skill, implacability, as well as determination not to accept failure. ~ Admiral Arleigh A. Burke
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups