Shell script Copy file from one directory to another not working

13,086

Word-Splitting

Protect your parameter strings and expansions from word-splitting by wrapping them in "quotes". Notice how the following examples are colour-coded differently? It's revealing the differences between how the words are being grouped and separated.

You may or may not actually even need to \ escape\ the file path's white-space anymore, either.


Quoted

src="/var/lib/jenkins/jobs/Android\ Gradle\ test\ build/workspace/MainApp/app/src/main/res/drawable-hdpi/logo_splash.png"
dest="/var/lib/jenkins/jobs/Android\ Gradle\ test\ build/workspace/MainApp/app/src/main/res/drawable/logo_splash.png"

cp -rf  "$src" "$dest"

Un-Quoted

SRC=/var/lib/jenkins/jobs/Android\ Gradle\ test\ build/workspace/MainApp/app/src/main/res/drawable-hdpi/logo_splash.png
DEST=/var/lib/jenkins/jobs/Android\ Gradle\ test\ build/workspace/MainApp/app/src/main/res/drawable/logo_splash.png

cp -rf  $SRC $DEST
Share:
13,086

Related videos on Youtube

Nagaraj ks
Author by

Nagaraj ks

Updated on September 18, 2022

Comments

  • Nagaraj ks
    Nagaraj ks over 1 year

    Hi I am trying to automate the android build system through jenkins. Here I am trying to copy the image file from one directory to another directory but always getting " No such file or directory"

    SRC=/var/lib/jenkins/jobs/Android\ Gradle\ test\ build/workspace/MainApp/app/src/main/res/drawable-hdpi/logo_splash.png
    DEST=/var/lib/jenkins/jobs/Android\ Gradle\ test\ build/workspace/MainApp/app/src/main/res/drawable/logo_splash.png
    
    cp -rf  $SRC $DEST
    

    Error log: cp: target `build/workspace/MainApp/app/src/main/res/drawable/logo_splash.png' is not a directory

  • Nagaraj ks
    Nagaraj ks about 8 years
    Yeah I missed the quotes, now I able to copy. Thanks
  • Nagaraj ks
    Nagaraj ks about 8 years
    Yeah I missed the quotes, now I able to copy. Thanks