🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #15648

ALguien preguntaba sobre nombres con espacios?

#15648
From: Santiago Romero
Date: Sat, 10 Jun 2000 00:00
55 lines
2601 bytes
 Para los que preguntaban sobre errores en los scripts si
 los nombres tenian espacios entre ellos:

Use $* instead of "$@"

  You probably know the difference between "$@" and $*. Both stand for
  "all arguments  specified on the  command line". "$@"  does preserve
  whitespace, while $* does not.

  Just ignore this certainly neglectable difference. If users use file
  names containing whitespace, they will have other problems than your
  failing script.  Who can expect  you to search  the "@" key  on your
  keyboard if the "*" key is so near?

  Just use for-loops of the following form:

                      # remove - remove files
                      for file in $*
                      do
                          echo "$file does no longer contain whitespace"
                          rm -f $file
                      done

  If  somebody  calls this  remove  script  with the  single  argument
  "/etc/passwd Backup", he should have expected to lose some data.

  If you had written the script in  one of the following ways it would
  have worked:

                      for file in "$@"
                      do
                          # ...
                      done

   or shorter: 

                      for file
                      do
                          # "$file" still contains whitespace...
                      done

   But why care? Just  be sure to include a sentence  like "in case of
   difficulties restore data from  the backup" within your documentation.

--

Ley de la Garant�a: Cuanto m�s cuesta un aparato, m�s lejos tienes que
mandarlo para que lo arreglen.
 _-----------------------------------------------------_
|  NoP / Compiler       --     sromero@unix-shells.com  |
|-------------------------------------------------------|
|  POWERED BY - Linux RedHat 6.0  -  Reg. User #74.821  |
|              http://web.jet.es/s.romero               |
 ~-----------------------------------------------------~
Technical Details
Message-ID: <slrn8k4488.59d.sromero@compiler.linux.es>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f86c8,2348c41b280ef63e,start
X-Google-Attributes: gidf86c8,public
From: sromero@unix-shells.com (Santiago Romero)
Subject: ALguien preguntaba sobre nombres con espacios?
Date: 2000/06/10
Message-ID: <slrn8k4488.59d.sromero@compiler.linux.es>
X-Deja-AN: 633403417
Content-Transfer-Encoding: 8bit
Organization: Telefonica Transmision de Datos
Content-Type: text/plain; charset=iso-8859-1
User-Agent: slrn/0.9.6.2 (Linux)
Mime-Version: 1.0
Reply-To: sromero@unix-shells.com
Newsgroups: es.comp.os.linux.programacion