Find Command, I want to use my variables

Multi tool use
Multi tool use

The name of the pictureThe name of the pictureThe name of the pictureClash 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.










share|improve this question



















  • 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 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











  • Why ksh and exec bash ? Perhaps you can try to export your variables before calling find.
    – ctac_
    7 hours ago














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.










share|improve this question



















  • 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 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











  • Why ksh and exec bash ? Perhaps you can try to export your variables before calling find.
    – ctac_
    7 hours ago












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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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











  • Why ksh and exec bash ? Perhaps you can try to export your variables before calling find.
    – ctac_
    7 hours ago












  • 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 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











  • 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















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































eBPkG60Nf,s bLpUNb3FjSlQY4Sc U3N PNQYRu4L8RtV,pUA31LwM6K
PsPqyL 5AHyMJw4HdkukUi7VpHGb5mmuTCENyLjuNOhKQbN Pqx2kooSd SErMh1DKZCg7E

Popular posts from this blog

How to check contact read email or not when send email to Individual?

How many registers does an x86_64 CPU actually have?

Displaying single band from multi-band raster using QGIS