What is the meaning of "foo" and $foo"?

What is the meaning of "foo" and $foo"?

Post by Lamar Thoma » Sun, 19 Jan 2003 16:16:25



I am running RH 7.3

I am installing a program called "horde" and one of the steps having me
running this command on all the files in a directory:  #  for foo in *.dist;
do cp $foo 'basename $foo .dis'; done

This is a list of the files in that directory:

horde.php.dist
html.php.dist
lang.php.dist
mime_mapping.php.dist
mime_drivers.php.dist
motd.php.dist
prefs.php.dist
registry.php.dist

What is that command and what does it do?  Thanks for any help.

Lamar

 
 
 

What is the meaning of "foo" and $foo"?

Post by Spamles » Sun, 19 Jan 2003 16:46:05



> I am running RH 7.3

> I am installing a program called "horde" and one of the steps having me
> running this command on all the files in a directory:  #  for foo in *.dist;
> do cp $foo 'basename $foo .dis'; done

FUBAR (F*cked up beyond all recognition)

As a joke, may items that need one or two generic names will
use names "foo" (and if it needs a second generic name, "bar").

In this cas "foo" is being used as a variable.

Using the bash shell

 for var in *.dist

for a loop will loop "var" through all the files:

 a.dist, b.dist, c.dist, my_mother_the_car.dist, Henry.dist

 etc. (all *.dist files)

So what does:

 for var in *.dist
  do
   cp $var 'basename $var .dis'
  done

Hmmm ... are you sure it wasn't:

 for var in *.dist
  do
   cp $var `basename $var .dist`
  done

(there is a gigantic difference between ` and '
 `command` puts the output of the command right there!
 'string' marks a string)

Well, the script you had uses the variable foo
(foo when you set it, $foo when you use it) instead
of var.

basename file ext

does the following:

It removes any path before the filename and removes
the extension (if one is given).

For example:

 basename /this/path/myfile.txt

returns

 myfile.txt

while

 basename /this/path/myfile.txt .txt

returns

 myfile

So ... what you have is a loop.

For each value of the variable $foo
(which will go through all the files
with names SOMETHING.dist)

it does a

 cp $foo `basename $foo .dist`

This is a copy command.

If foo is the file:

 /my/directory/junk.dist

this will become:

 cp /my/directory/junk.dist junk

(it makes a copy of the file without any
pathname or extension - that is, just copies
the files and gets rid of the extension)

 >

Quote:> This is a list of the files in that directory:

> horde.php.dist
> html.php.dist
> lang.php.dist
> mime_mapping.php.dist
> mime_drivers.php.dist
> motd.php.dist
> prefs.php.dist
> registry.php.dist

> What is that command and what does it do?  Thanks for any help.

It will copy the files to:

horde.php
html.php
lang.php
mime_mapping.php
etc.

See:

 man bash

and look for the "for" command.

Also look for the section on
"Command Substitution" (the "backtick expansion" used
above) and

 man basename

for what the basename command does.

 
 
 

What is the meaning of "foo" and $foo"?

Post by Guido Drahei » Sun, 19 Jan 2003 20:27:57


Spamless schrieb:


>>I am running RH 7.3

>>I am installing a program called "horde" and one of the steps having me
>>running this command on all the files in a directory:  #  for foo in *.dist;
>>do cp $foo 'basename $foo .dis'; done

> FUBAR (F*cked up beyond all recognition)

> As a joke, may items that need one or two generic names will
> use names "foo" (and if it needs a second generic name, "bar").

> In this cas "foo" is being used as a variable.

 > [followed by an great explanation of what it actually does]

ethymology of `foo`:
    http://www.google.com/search?q=foo+jargon

in this case:
    hackers should be warned - do not write annoying code unecessarily,
    or people will come up with a `trouble ticket` later. There would
    have been nothing wrong with using `f` instead of `foo`, or even
    the unworthy `filename`.... :-)=)

cheers, guido                                   counter.li.org #81555
p.s. a whopping crosspost to four newsgroups, wheeewww...

 
 
 

What is the meaning of "foo" and $foo"?

Post by Mark Scot » Sun, 19 Jan 2003 23:26:06



> See:

>  man bash

> and look for the "for" command.

Someone I found by accident the other day:

When you're using bash, just type "help" for a quick look at all the
bash commands, or "help for" for information on how to use "for".

--
Mark Scott

 
 
 

What is the meaning of "foo" and $foo"?

Post by Christopher Brown » Mon, 20 Jan 2003 14:31:17



Quote:> in this case:
>     hackers should be warned - do not write annoying code unecessarily,
>     or people will come up with a `trouble ticket` later. There would
>     have been nothing wrong with using `f` instead of `foo`, or even
>     the unworthy `filename`.... :-)=)

.. Except that the "foo" variable name convention doesn't necessarily
indicate that you're trying to annoy in any way.
--

http://www.ntlug.org/~cbbrowne/internet.html
"I think fish is nice, but then I think that rain  is wet, so who am I
to judge?"  -- Ruler of the Universe, HHGTTG
 
 
 

What is the meaning of "foo" and $foo"?

Post by Doug » Mon, 20 Jan 2003 14:38:34




>> in this case:
>>     hackers should be warned - do not write annoying code unecessarily,
>>     or people will come up with a `trouble ticket` later. There would
>>     have been nothing wrong with using `f` instead of `foo`, or even
>>     the unworthy `filename`.... :-)=)

> .. Except that the "foo" variable name convention doesn't necessarily
> indicate that you're trying to annoy in any way.

You should see some of the old assembly code I used to work on.

The source code was full of interesting comments.

    'This data is
    'used for
    'replying to
    'data calls

Think about it. ;)  t  u  r  ....

--DougW--

 
 
 

What is the meaning of "foo" and $foo"?

Post by Robert Bindle » Mon, 20 Jan 2003 14:38:49




> (there is a gigantic difference between ` and '
>  `command` puts the output of the command right there! 'string' marks a
>  string)

So I guess my bash isn't messed up! There's tons of scripts that I've
tried, which never worked for some strange reason...

--
eel tech
http://www.hostultra.com/~someguy456/index.htm

 
 
 

What is the meaning of "foo" and $foo"?

Post by Robert Bindle » Mon, 20 Jan 2003 14:42:38




>> in this case:
>>     hackers should be warned - do not write annoying code unecessarily,
>>     or people will come up with a `trouble ticket` later. There would
>>     have been nothing wrong with using `f` instead of `foo`, or even the
>>     unworthy `filename`.... :-)=)

> .. Except that the "foo" variable name convention doesn't necessarily
> indicate that you're trying to annoy in any way.

My CS professor uses foo and bar almost exclusively in his lectures, (Data
Structures)

--
eel tech
http://www.hostultra.com/~someguy456/index.htm

 
 
 

What is the meaning of "foo" and $foo"?

Post by Robert Bindle » Mon, 20 Jan 2003 14:48:13





>>> in this case:
>>>     hackers should be warned - do not write annoying code unecessarily,
>>>     or people will come up with a `trouble ticket` later. There would
>>>     have been nothing wrong with using `f` instead of `foo`, or even
>>>     the unworthy `filename`.... :-)=)

>> .. Except that the "foo" variable name convention doesn't necessarily
>> indicate that you're trying to annoy in any way.

> You should see some of the old assembly code I used to work on.

> The source code was full of interesting comments.

>     'This data is
>     'used for
>     'replying to
>     'data calls

> Think about it. ;)  t  u  r  ....

> --DougW--

Do a "grep -R <word> /usr/src/linux/" where word is any curse word. You'll
be surprised at what you find. Here's some stuff:

* Why in the hell did I put these inside #ifdef's?

* If you don't see why, please stay the * away from my code.

* (And this is the *ing 'basic' method).

* Wirzenius wrote this portably, Torvalds *ed it up :-)

* Have to manually jack-slap that *!

I want to see Microsoft do beter than this...
--
eel tech
http://www.veryComputer.com/~someguy456/index.htm

 
 
 

What is the meaning of "foo" and $foo"?

Post by Eric P. McC » Mon, 20 Jan 2003 18:43:40



> .. Except that the "foo" variable name convention doesn't necessarily
> indicate that you're trying to annoy in any way.

"Annoying" isn't some intrinsic trait; it's a trait ascribed to a
thing by others.  A thing isn't annoying because of something
fundamentally wrong with it; a thing is annoying because people say it
is, and for no other reason.  If more people than not say that
something is annoying, then generally it's accepted to be such.

Or, in short, the intent has nothing to do with it.

--

"Last I checked, it wasn't the power cord for the Clue Generator that
was sticking up your ass." - John Novak, rasfwrj

 
 
 

What is the meaning of "foo" and $foo"?

Post by Eric P. McC » Mon, 20 Jan 2003 18:51:22



> Do a "grep -R <word> /usr/src/linux/" where word is any curse word. You'll
> be surprised at what you find.

Not really, no.

Quote:> Here's some stuff:
> * If you don't see why, please stay the * away from my code.
> * (And this is the *ing 'basic' method).
> * Wirzenius wrote this portably, Torvalds *ed it up :-)
> * Have to manually jack-slap that *!
> I want to see Microsoft do beter than this...

I want to see _Linux_ do better than this.  There's no excuse for
profanity in code, whether it's in a common message or in the
comments.  It's insulting to the intelligence of the reader and
reflects poorly on the intelligence of the author.  It's
unprofessional and makes the entire product look like something thrown
together by a bunch of immature little children.

There's a time and a place for informal writing (including profanity),
and that place is _not_ inside an operating system you're trying to
convince large businesses to use.  Nobody's saying you need perfect
grammar or need to use IBM-style wordiness,[1] but programmers also
need to understand they aren't talking to their best friends at a
bar.

[1] The specified specification cannot be specified as specified;
    check the specification in "IBM Operating System Error Message
    Specification Message Specification, Volume 3: Advanced
    Specifications and Systems" for the precise error message
    specification message specification as it relates to this advanced
    specification and/or system, then try again.

--

"Last I checked, it wasn't the power cord for the Clue Generator that
was sticking up your ass." - John Novak, rasfwrj

 
 
 

What is the meaning of "foo" and $foo"?

Post by W. Citoa » Mon, 20 Jan 2003 22:53:17



> I want to see _Linux_ do better than this.  There's no excuse for
> profanity in code, whether it's in a common message or in the
> comments.  It's insulting to the intelligence of the reader and
> reflects poorly on the intelligence of the author.  It's
> unprofessional and makes the entire product look like something thrown
> together by a bunch of immature little children.

Then re-write the comments yourself and submit patches!  Linux has been
written primarily by people doing it for their own needs and for fun.  It's
insulting to them to tell them that the free labor you are benefiting from
is the work "of immature little children."

As for foo|bar -- it has become common terminology for two variables in
examples.  It ethymology is unknown to most people.  Their usage has become
as generic as i and j for counter variables.  

- W. Citoan

 
 
 

What is the meaning of "foo" and $foo"?

Post by Charles Sulliva » Mon, 20 Jan 2003 22:36:36






>>> in this case:
>>>     hackers should be warned - do not write annoying code
>>>     unecessarily, or people will come up with a `trouble ticket`
>>>     later. There would have been nothing wrong with using `f` instead
>>>     of `foo`, or even the unworthy `filename`.... :-)=)

>> .. Except that the "foo" variable name convention doesn't necessarily
>> indicate that you're trying to annoy in any way.

> My CS professor uses foo and bar almost exclusively in his lectures,
> (Data Structures)

Use of "foo" drove me nuts many years ago when I was just starting
to learn how to write assembly code.  It was hard to figure out
whether the typo-ridden manual was referring to a literal or a label
named foo or the value 0xF00.
 
 
 

What is the meaning of "foo" and $foo"?

Post by Tony Lawrenc » Mon, 20 Jan 2003 23:03:57




>>Do a "grep -R <word> /usr/src/linux/" where word is any curse word. You'll
>>be surprised at what you find.

> Not really, no.

>>Here's some stuff:

>>* If you don't see why, please stay the * away from my code.
>>* (And this is the *ing 'basic' method).
>>* Wirzenius wrote this portably, Torvalds *ed it up :-)
>>* Have to manually jack-slap that *!

>>I want to see Microsoft do beter than this...

> I want to see _Linux_ do better than this.  There's no excuse for
> profanity in code, whether it's in a common message or in the
> comments.  It's insulting to the intelligence of the reader and
> reflects poorly on the intelligence of the author.  It's
> unprofessional and makes the entire product look like something thrown
> together by a bunch of immature little children.

Strictly speaking, it's not profanity.  It's vulgarity, and the origin
of THAT is nothing but class discrimination.  Some dictionaries nowadays
muddle these together, which I think is a shame.

Profanity is perhaps disrespectful of other's belief systems, though
many of us, religious and non religious, are quite apt to use mildly
"profane" speech in ordinary conversation and it is generally quite
acceptable.

Vulgarity is, imho, ridiculous to complain about when you understand its
origins.

--
Tony Lawrence
Free SCO, Mac OS X and  Linux Skills Tests:
http://www.veryComputer.com/

 
 
 

What is the meaning of "foo" and $foo"?

Post by B. Joshua Rose » Tue, 21 Jan 2003 01:32:58




>> I am running RH 7.3

>> I am installing a program called "horde" and one of the steps having me
>> running this command on all the files in a directory:  #  for foo in
>> *.dist; do cp $foo 'basename $foo .dis'; done

> FUBAR (F*cked up beyond all recognition)

> As a joke, may items that need one or two generic names will use names
> "foo" (and if it needs a second generic name, "bar").

> In this cas "foo" is being used as a variable.

FUBAR originated during World War II to refer to the general state of
disorder in the US Army. Back when computers were designed on paper,
which wasn't all that long ago, low true signals had a line drawn over the
signal name which was called "BAR". Thus if you had a signal named FOO
and you inverted it, you would name the inverted signal FOO with a BAR
line over it and called FOOBAR. Thus FOOBAR was an in joke because a
non-engineer looking at a schematic would see the only the word FOO with
a mysterious line drawn over it, whereas any engineer would know that it
was pronounced FOOBAR an thus had a slightly profane meaning. From those
origins the names FOO and BAR made the jump to software where they are
used as generic names for just about everything. FOO and BAR have always
been central to the hacker culture from the very start of the computer
technology.