LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-02-2009, 06:01 PM   #1
raptorred
LQ Newbie
 
Registered: Aug 2009
Posts: 2

Rep: Reputation: 0
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.
 
Old 08-02-2009, 06:19 PM   #2
Meson
Member
 
Registered: Oct 2007
Distribution: Arch x86_64
Posts: 606

Rep: Reputation: 67
I think that ~ isn't being expanded to /home/$USER
 
Old 08-02-2009, 06:45 PM   #3
raptorred
LQ Newbie
 
Registered: Aug 2009
Posts: 2

Original Poster
Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with bash script - variable name within variable name steven.c.banks Linux - Newbie 3 03-10-2009 03:08 AM
Reading a bash variable in bash scripting problem freeindy Programming 3 11-27-2008 02:29 AM
BASH if/elif variable problem GNUJoshua Programming 6 07-15-2008 07:01 AM
Bash Awk Variable problem _hadi_ Programming 5 12-13-2006 12:25 AM
Bash Variable Problem decates Linux - Newbie 10 01-28-2003 10:47 PM


All times are GMT -5. The time now is 02:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration