Find Command, I want to use my variables
Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
I have a script that creates a new directory based on User Input, and well as which directory contents it will copy over. Now here is where I am having issues, I have a find command that will replace files that have a specific name in front and replace it with the new name. It works, but I want to use the variables that I've created instead of a changing the string I have set, I keep getting an error saying it can't do it, please assist?
#Creates Directory
echo "Name of New Directory"
read userInput
if [[ -n "$newdir" ]]
then
mkdir $newdir
fi
echo $newdir Directory Created
echo
echo "Directory you wish to Copy?"
read copydir
if [[ -n "$copydir" ]]
then
#Copies contents of Specified Directory
cp -R $copydir/!(*.UNC) $newdir;
#Searches through directory
find $newdir/ -name "$copydir*" -exec bash -c 'f="$1"; mv "$f" "$f/sppark/work"' - ;
fi
So instead of sppark and work, I want to use my variables newdir and copydir, in the Find command.
scripting ksh
add a comment |Â
up vote
-1
down vote
favorite
I have a script that creates a new directory based on User Input, and well as which directory contents it will copy over. Now here is where I am having issues, I have a find command that will replace files that have a specific name in front and replace it with the new name. It works, but I want to use the variables that I've created instead of a changing the string I have set, I keep getting an error saying it can't do it, please assist?
#Creates Directory
echo "Name of New Directory"
read userInput
if [[ -n "$newdir" ]]
then
mkdir $newdir
fi
echo $newdir Directory Created
echo
echo "Directory you wish to Copy?"
read copydir
if [[ -n "$copydir" ]]
then
#Copies contents of Specified Directory
cp -R $copydir/!(*.UNC) $newdir;
#Searches through directory
find $newdir/ -name "$copydir*" -exec bash -c 'f="$1"; mv "$f" "$f/sppark/work"' - ;
fi
So instead of sppark and work, I want to use my variables newdir and copydir, in the Find command.
scripting ksh
1
Changed the Title, I require assistance with my Find command, I want to use my variables $newdir and $copydir, instead of "$f/sppark/work", where newdir is work and copydir is sppark
â Josh Adams
7 hours ago
you could userename
instead ofmv
..
â RoVo
7 hours ago
That was my first guess, butrename
doesn't exist in my environment, and I can't just download it, somv
is next best
â Josh Adams
7 hours ago
Why ksh and exec bash ? Perhaps you can try to export your variables before calling find.
â ctac_
7 hours ago
add a comment |Â
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I have a script that creates a new directory based on User Input, and well as which directory contents it will copy over. Now here is where I am having issues, I have a find command that will replace files that have a specific name in front and replace it with the new name. It works, but I want to use the variables that I've created instead of a changing the string I have set, I keep getting an error saying it can't do it, please assist?
#Creates Directory
echo "Name of New Directory"
read userInput
if [[ -n "$newdir" ]]
then
mkdir $newdir
fi
echo $newdir Directory Created
echo
echo "Directory you wish to Copy?"
read copydir
if [[ -n "$copydir" ]]
then
#Copies contents of Specified Directory
cp -R $copydir/!(*.UNC) $newdir;
#Searches through directory
find $newdir/ -name "$copydir*" -exec bash -c 'f="$1"; mv "$f" "$f/sppark/work"' - ;
fi
So instead of sppark and work, I want to use my variables newdir and copydir, in the Find command.
scripting ksh
I have a script that creates a new directory based on User Input, and well as which directory contents it will copy over. Now here is where I am having issues, I have a find command that will replace files that have a specific name in front and replace it with the new name. It works, but I want to use the variables that I've created instead of a changing the string I have set, I keep getting an error saying it can't do it, please assist?
#Creates Directory
echo "Name of New Directory"
read userInput
if [[ -n "$newdir" ]]
then
mkdir $newdir
fi
echo $newdir Directory Created
echo
echo "Directory you wish to Copy?"
read copydir
if [[ -n "$copydir" ]]
then
#Copies contents of Specified Directory
cp -R $copydir/!(*.UNC) $newdir;
#Searches through directory
find $newdir/ -name "$copydir*" -exec bash -c 'f="$1"; mv "$f" "$f/sppark/work"' - ;
fi
So instead of sppark and work, I want to use my variables newdir and copydir, in the Find command.
scripting ksh
scripting ksh
edited 24 mins ago
Rui F Ribeiro
37.1k1274118
37.1k1274118
asked 7 hours ago
Josh Adams
195
195
1
Changed the Title, I require assistance with my Find command, I want to use my variables $newdir and $copydir, instead of "$f/sppark/work", where newdir is work and copydir is sppark
â Josh Adams
7 hours ago
you could userename
instead ofmv
..
â RoVo
7 hours ago
That was my first guess, butrename
doesn't exist in my environment, and I can't just download it, somv
is next best
â Josh Adams
7 hours ago
Why ksh and exec bash ? Perhaps you can try to export your variables before calling find.
â ctac_
7 hours ago
add a comment |Â
1
Changed the Title, I require assistance with my Find command, I want to use my variables $newdir and $copydir, instead of "$f/sppark/work", where newdir is work and copydir is sppark
â Josh Adams
7 hours ago
you could userename
instead ofmv
..
â RoVo
7 hours ago
That was my first guess, butrename
doesn't exist in my environment, and I can't just download it, somv
is next best
â Josh Adams
7 hours ago
Why ksh and exec bash ? Perhaps you can try to export your variables before calling find.
â ctac_
7 hours ago
1
1
Changed the Title, I require assistance with my Find command, I want to use my variables $newdir and $copydir, instead of "$f/sppark/work", where newdir is work and copydir is sppark
â Josh Adams
7 hours ago
Changed the Title, I require assistance with my Find command, I want to use my variables $newdir and $copydir, instead of "$f/sppark/work", where newdir is work and copydir is sppark
â Josh Adams
7 hours ago
you could use
rename
instead of mv
..â RoVo
7 hours ago
you could use
rename
instead of mv
..â RoVo
7 hours ago
That was my first guess, but
rename
doesn't exist in my environment, and I can't just download it, so mv
is next bestâ Josh Adams
7 hours ago
That was my first guess, but
rename
doesn't exist in my environment, and I can't just download it, so mv
is next bestâ Josh Adams
7 hours ago
Why ksh and exec bash ? Perhaps you can try to export your variables before calling find.
â ctac_
7 hours ago
Why ksh and exec bash ? Perhaps you can try to export your variables before calling find.
â ctac_
7 hours ago
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f476323%2ffind-command-i-want-to-use-my-variables%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Changed the Title, I require assistance with my Find command, I want to use my variables $newdir and $copydir, instead of "$f/sppark/work", where newdir is work and copydir is sppark
â Josh Adams
7 hours ago
you could use
rename
instead ofmv
..â RoVo
7 hours ago
That was my first guess, but
rename
doesn't exist in my environment, and I can't just download it, somv
is next bestâ Josh Adams
7 hours ago
Why ksh and exec bash ? Perhaps you can try to export your variables before calling find.
â ctac_
7 hours ago