Shell Script: Copy directory passed as variable to another directory also as variable passed by user

StackOverflow https://stackoverflow.com/questions/15801599

  •  01-04-2022
  •  | 
  •  

質問

SHELL SCRIPT: How can i copy a directory passed as a variable by user to another directory also as variable?

I mean, the user type a source directory and the destination. So, the files into directory are copied to the other directory.

役に立ちましたか?

解決

if cp -R "$source" "$destination"
then echo "Copy successful :)"
else echo "Copy failed :("
fi

The -R option to cp specifies that it should copy the directory recursively. $source should contain the original directory, and $destination should contain the location where you want it copied.

他のヒント

If you want to do something like this:

$ ./script.sh file1.ext file2.ext

The script.sh could be:

#!/bin/bash
cp -rv "$0" "$1"

Hope it helps.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top