Linux copy all content of a directory to Another directory via Bash, String Manipulation

Viewed 28

My question is very simple and I'm ashamed of myself for asking such a question like this, but I'm trying to learn Linux and I can't find a way to use these strings.

#!/bin/bash

SOURCE = '/home/admins/tryA'
DESTINATION = '/home/admins/tryB'

cp -r '$SOURCE'/* '$DESTINATION'

#cp -r /home/admins/tryA/* /home/admins/tryB

As in the comment line, the command works when I don't use variables, but I get an error when I use the variables. Can you briefly tell me what I'm doing wrong?

Error is this:

./run.sh: line 4: =: command not found
./run.sh: line 5: =: command not found
cp: target '' is not a directory

Thanks.

2 Answers

Just take away the ' ' around the variables in the cp command

This should work:

#!/bin/bash

SOURCE=/home/admins/tryA
DESTINATION=/home/admins/tryB

cp -r $SOURCE/* $DESTINATION
Related