Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, I was thinking of writing a script to segregate my ebooks and put them in their corresponding directory. And i wrote a script which searches for the file with ...
  1. #1
    Just Joined! mkannan555's Avatar
    Join Date
    Mar 2007
    Posts
    6

    "cannot stat :No such file or directory " error in script

    Hi, I was thinking of writing a script to segregate my ebooks and put them in their corresponding directory. And i wrote a script which searches for the file with give key word in the current directory and copies them to a specified directory.

    here is the script
    Code:
    if [ $# -eq 0 ]
    then
    
    echo "few arguments supplied"
    exit 1
    
    fi
    
    IFS=,
    
    files=`ls -mQ|grep -i $1`
    
    for file in $files
    do
    
    file=`echo $file|tr -s '\n' ' '`
    
    #echo $file
    cp $file ~/tmp
    
    done
    but when i run this script i get the error message like the below for all files

    cannot stat ` "Professional Java Development With The Spring Framework (2005).chm" ': No such file or directory


    so what am i doing wrong, can u guys help me

    thanks in advance

    M.Kannan

  2. #2
    Linux Guru sdousley's Avatar
    Join Date
    Feb 2004
    Posts
    1,789
    The problem you are likely having here is that the file:

    Professional Java Development With The Spring Framework (2005).chm doesn't exist.

    If you were to tab-complete this, you would get:

    Professional\ Java\ Development\ With\ The\ Spring\ Framework\ \(2005\).chm

    Been a while since i did Bash, but I *THINK* if you quote the $file at the end

    Code:
    cp "$file" ~/tmp
    That should be fine.
    "I am not an alcoholic, alcoholics go to meetings"
    Registered Linux user = #372327

  3. #3
    Just Joined! mkannan555's Avatar
    Join Date
    Mar 2007
    Posts
    6
    yes i tried the same as u said, but still i am getting the same problem, any other suggestions please..

  4. #4
    Linux Enthusiast
    Join Date
    Aug 2006
    Location
    Portsmouth, UK
    Posts
    539
    Code:
     grep -l '$1' * | xargs -I{} cp {} ~/tmp/.
    Should do the trick
    RHCE #100-015-395
    Please don't PM me with questions as no reply may offend, that's what the forums are for.

Posting Permissions

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