LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash Variable Problem (https://www.linuxquestions.org/questions/linux-newbie-8/bash-variable-problem-744619/)

raptorred 08-02-2009 06:01 PM

Bash Variable Problem
 
Hi ive been using linux for a while but I am just getting into shell scripting, im currently trying to get a simple script for finding and copying files powered by the command:
Code:

find . -name "*.doc" 2>&1|grep -iv denied|sed "s/\([^A-Za-z0-9]\)/\\\\\1/g"|xargs -ivar cp "var" ~/test
this works fine from the command line but when put in a script such as:
Code:

#!/bin/bash
echo "What would you like to Find?"
read fc1
echo "Where do you want to copy files?"
read fc2
find . -name "$fc1" 2>&1|grep -iv denied|sed "s/\([^A-Za-z0-9]\)/\\\\\1/g"|xargs -ivar cp "var" $fc2

it outputs:
Code:

cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
cp: cannot create regular file `~/test': No such file or directory
......

with the keyboard inputs for $fc1 and $fc2 being *.doc and ~/test respectivly. The only problem i can see is the xargs -ivar "var" part possibly needing $var to be defined? Any help appreciated.

Meson 08-02-2009 06:19 PM

I think that ~ isn't being expanded to /home/$USER

raptorred 08-02-2009 06:45 PM

Ack! thought i had tested that must of made a typo, no more un-caffinated coding for me, and yeah that works fine now thanks :)


All times are GMT -5. The time now is 04:18 AM.