Shared publicly  - 
I made some major changes to my #sed tutorial  - which now includes the GNU sed command line options. Feedback, gang?
Bruce Barnett's profile photoIlya Gordeev's profile photoDavid Farrow's profile photoJeroen Valcke's profile photo
hey bruce, i was going through your bourne shell tutorial.
In the following example :

a=one; echo $a
a=two echo $a
a=three echo $a >$a

you said that 3rd line will create file named "three". But i tried on bash and it created file named "one" and content was also "one". Am i missing anything.
And one more thing, when we change a environment variable, suppose HOME=/ , then in bash, without "export" command the new value is reflected in the o/p of "set" command. Is it ok?
Once you mark a variable as  exportable, you can change it and do not need to export it again.  the command "set" shows all variables, while "env" just shows environment variables. "set" is a shell built-in command so it knows non-exported variables. "env" is a separate executable, and therefore it only inherits exported variables. The "local" i.e. non-exported ones - are not seen by "env".  I hope that is clear.
Also the example you mention is one of those strange cases where different versions of bash will do different things. I get one value, and a year later with a new version of bash I get a different value. Yeah. Fun, eh?
Prateek - I added a new update on that section, and also listed you in the "Thanks" section. Yes - I get the same answer that you get.
Thanks Bruce for explanation. But i want some more clarification. You said, "Once you mark a variable as  exportable, you can change it and do not need to export it again."  But i did not even exported my variable and it was usable with new value. I am confused!! :-(
First of all, remember that when you use arguments like [a-z]* and [A-Z]* that there are two stages. The first is the shell expansion of the parameters. The seconds is how the command (in your case 'ls' ) evaluates the arguments.

To see what is happening in the first stage, put echo before the command

echo ls [a-z]*
echo ls [A-Z]*

Then - remember that 'ls' when given a directory, will list the contents of the directory instead of the file. Try
ls -d [a-z]*
ls -d [A-Z]*

I bet if you do this it will no longer be strange.
just came across your site, helped me out w/ a quick sed fix.  Thank you
Isn't the eqvivalent to the following?

/ONE/ {
I think you are right! Thanks. I'll have to add this as a note.
Marvelous article! A lot of things was a revelation. Thank you for sharing it!
Thanks for the great tutorial!

I found a small typo which you might could fix with a "sed s/genertae/generate/" :)
Love the tutorial, thanks. I'm left puzzled by the amended example. Why doesn't
echo "abc 123" | sed 's/[0-9]*/& &/'
abc 123 abc 123
Since it's greedy it matches the entire line, no?
Add a comment...