Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: #!/bin/bash

  1. #11
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,468
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: #!/bin/bash

    did you quote variables in cp call? unquoted vars undergo word splitting on spaces, so assuming file="a b c"; dest="d e f";
    cp $file $dest becomes cp 'a' 'b' 'c' 'd' 'e' 'f', not cp 'a b c' 'd e f'
    cp "$file" "$dest" would properly yield cp 'a b c' 'd e f'

    in your case cp would try to find 2 files and of course fail:
    ${HOME}/Desktop/Office
    Briefcase/HSI Work/WorkRecord.md
    Last edited by Vaphell; September 1st, 2014 at 06:01 PM.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  2. #12
    Join Date
    Aug 2013
    Beans
    42

    Re: #!/bin/bash

    Yes, I used this:

    cp "$FILE" "$DESTINATION"

    I'm STUMPED!

  3. #13
    Join Date
    Mar 2006
    Location
    North Carolina
    Beans
    394

    Re: #!/bin/bash

    Try this:
    FILE=/home/{your home directory}/Desktop/'Office Briefcase'/'HSI Work'/WorkRecord.md
    Leave out the braces.

  4. #14
    Join Date
    Aug 2013
    Beans
    42

    Re: #!/bin/bash

    Like this?

    File=/home/larry/Desktop/'Office Briefcase'/'HSI Work'/WorkRecord.md
    Destination=/home/larry/
    Same error message

  5. #15
    Join Date
    Apr 2012
    Beans
    6,120

    Re: #!/bin/bash

    Can I suggest you copy/paste the ENTIRE script here so we can have a proper look at it, plus the actual command(s) you are using to run it? e.g.

    Code:
    $ cat myscript.sh
    #!/bin/bash
    
    file="$HOME/Desktop/some file"
    dest="$HOME"
    
    cp "$file" "$dest"
    then (assuming you have made the script executable e.g. using 'chmod +x myscript.sh' or equivalent from the file manager)

    Code:
    $ ./myscript.sh
    cp: cannot stat `/home/steeldriver/Desktop/some file': No such file or directory

  6. #16
    Join Date
    Aug 2013
    Beans
    42

    Re: #!/bin/bash

    It seems to have something to do with the spaces in the directory names. I just did a test by creating a set of nested folders without spaces in the names. This script works flawlessly:

    File=${HOME}/Desktop/Test/Work/WorkRecord.md
    Destination=${HOME}


  7. #17
    Join Date
    Aug 2013
    Beans
    42

    Re: #!/bin/bash

    This is my entire script. This one functions as expected. However, when I try to use it on a folder with spaces in the name, it breaks with the error message described above.

    #!/bin/bash


    File=${HOME}/Desktop/Test/Work/WorkRecord.md
    Destination=${HOME}


    # Copy file to working directory.
    cp "$File" "$Destination"


    echo "Preparing Work Report..."


    # Pause
    sleep 2s


    echo "Deploying Pandoc ...."


    pandoc -s -S --toc -c PanAm.css WorkRecord.md -o WorkRecord.html


    # Pause to let Pandoc work.
    sleep 3s


    # Move the report to the Desktop.
    mv WorkRecord.html ~/Desktop/




    # Delete working file
    echo "Cleaning Up......."


    rm WorkRecord.md


    echo "Report Complete."

  8. #18
    Join Date
    Apr 2012
    Beans
    6,120

    Re: #!/bin/bash

    ... it would be more helpful to post the version that doesn't work

Page 2 of 2 FirstFirst 12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •