Jakeimo
Jakeimo

Reputation: 61

Bash script for for copying all files in a directory and appending with filenameCopy

I want to copy all files in a given directory, into the same directory, with a new name (something like: filenameCOPY).

I've tried a few different methods (globbing, cat, cp) but have yet to succeed. Here is where my code is currently at:

#!/bin/bash
if [ "$#" = "1"]
then
    if test -d $1; then
        for file in $1/*; do
            //something
        done
    else
        echo "$1 is not a directory"
fi

Upvotes: 1

Views: 116

Answers (1)

simon
simon

Reputation: 16340

I think all you need is something like this:

for file in "$1"/*; do
    cp -- "$file" "${file}COPY"
done;

right?

Upvotes: 2

Related Questions