Re: yet another question on file names with spaces?

From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 02/20/05

  • Next message: tsiwut_at_yahoo.com: "bash script website"
    Date: 20 Feb 2005 14:41:40 GMT
    
    

    On Sun, 20 Feb 2005 at 08:55 GMT, Russell Goyder wrote:
    >
    > Chris, thanks for the help.
    >
    >>> a="first\ file.txt second\ file.txt"
    >>> echo $(ls "$a")
    >>
    >> What's echo for? And what's wrong with:
    >>
    >> ls first\ file.txt second\ file.txt
    >>
    >> Or:
    >>
    >> echo first\ file.txt second\ file.txt
    >>
    >> Or:
    >>
    >> printf "%s\n" first\ file.txt second\ file.txt
    >
    > I agree, the echo is redudant. I posted the message after some time
    > spent debugging my script and was just used to echoing! All of your
    > three suggestions above do indeed print out the names of the two files
    > on stdout. However, I do not have the file names hardcoded - I don't
    > know what they are before the script runs - see below.
    >
    > In answer to:
    >
    >> Why use a loop?
    >>
    >> printf "%s\n" "${b[@]}"
    >
    > and
    >
    >> How are you getting the file names?
    >
    > I used a loop because, if a="first\ file.txt second\ file.txt" then ls
    > $a and ls "$a" both fail. I am not really interested in ls, I am
    > interested in scp, but I am using ls because the same principle applies
    > (I think) and it is quicker to test. With ls $a, ls receives 4
    > arguments and with ls "$a" it receives 1.

        Why do you have two file names in the variable?

    > I am getting the file names via the following proceedure: For a given
    > directory, I find the files in it, then find the files in a directory
    > with the same name on a remote machine. I go through the local files
    > finding whether they are also on the remote machine. Those that are
    > present locally, but not remotely, I copy to the remote machine via scp.

       HOW are you doing it? Let's see the code. Working with spaces in
       filenames is not hard; we need to see what you are doing wrong.

    > I am writing a very primitive form of syncing script in order to mirror
    > two directories. This is part of updating a web site - the text files
    > (html, php etc) are quick to zip up, transfer and unpack on the server
    > - I transfer them all every time, but there are binary files such as
    > images and pdfs which I only want to transfer once. Say I add another
    > set of images to my images directory, I would run my script on that
    > directory and it would upload the necessary files.
    >
    > I have been doing this by hand for a number of years, but I am trying
    > to make it possible for the web site to be developed collaboratively by
    > people separated geographically. If I add some images to the site,
    > someone else would sync in the opposite way to that described above in
    > order to download the extra files before starting work, then upload any
    > further files introduced during that work.
    >
    > I would rather use rsync for this, but that is not an option right now
    > (with my current hosting provider). Although crude, once working, my
    > scripts will be good enough for the time being, and I am glad to be
    > finally learning some shell programming!
    >
    > This has turned into quite a long explanation! The bottom line is that
    > I can choose how I have the file names - I can put them in an array or
    > have them as a single variable in the usual space-separated list format
    > ($a above).

         You CANNOT put them in a space-separated list, because a space
         betweeen file names is no different from a space between parts of
         the name. (There are ways, but it's more trouble than you need.)

    > However, I can't see a way to supply the list to the scp
    > command in a way that works because scp $fileList gives one argument
    > per space-separated string and scp "$fileList" gives a single string,
    > neither of which correspond to file names.

         Show us HOW you are getting the file names, and we'll give you an
         answer.

    -- 
        Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
        ===================================================================
        My code (if any) in this post is copyright 2005, Chris F.A. Johnson
        and may be copied under the terms of the GNU General Public License
    

  • Next message: tsiwut_at_yahoo.com: "bash script website"

    Relevant Pages

    • Re: yet another question on file names with spaces?
      ... > What's echo for? ... know what they are before the script runs - see below. ... present locally, but not remotely, I copy to the remote machine via scp. ... images and pdfs which I only want to transfer once. ...
      (comp.unix.shell)
    • Re: gdi question
      ... when i have a script that outputs multiple thumbnails, some images are shown while others remain blank and are shown with the classic red "X" image place holder and it's alt text. ... echo "file_get_contents". ...
      (alt.php)
    • Re: use of ssh command and to find an entry is a file or directory
      ... In this script i have to check whether the dest_dir is a file or ... This sets variables on the REMOTE machine, ... echo DIR ...
      (comp.unix.shell)
    • Re: Batch converting jpegs into thumbnail images
      ... echo -n "shrink $I..." ... crops the images exactly as needed. ... That your script echoes the progress which images are cropped and by how ... many pixels, adds the entertainment factor in watching this script work. ...
      (comp.unix.shell)
    • Re: Creating server based image catalogs with Filemaker?
      ... I send incoming pics through a batchrename (also a filemaker ... I did not send you a script, but some calculation examples. ... Currently it holds over 15,000 images, and more are added ...
      (comp.databases.filemaker)