Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-09-2008
Registered User
 
Join Date: Jul 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
redirect cat to variable

hello
just i saw a really strange for cat

i have file (file1) contains line /home/rajiv/proj1/*.txt

now applied a commonds

DDPATH="$(cat file1)"
echo $DDPATH

it shows all the txt files in that folder like /home/rajiv/proj1/read1.txt /home/rajiv/proj1/read2.txt /home/rajiv/proj1/read3.txt ......

but i need only /home/rajiv/proj1/*.txt.
can anyone helps
shailesh
Sponsored Links
    #2  
Old 07-09-2008
Registered User
 
Join Date: Apr 2008
Location: Hyderabad, India
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Redirecting cat

this works..

DDPATH=`cat file1`
echo "$DDPATH"

whatever you do just make sure you double quote your DDPATH variable when you print (or rather echo!)

cheers,
Hemanth
Sponsored Links
    #3  
Old 07-09-2008
Registered User
 
Join Date: Jul 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
cat

oops not working...


also i want to use this variable further in my script
BR
shailesh
    #4  
Old 07-09-2008
radoulov's Avatar
--
 
Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 5,468
Thanks: 139
Thanked 538 Times in 506 Posts
What shell? Could you post the output that demonstrates expansion of the * with quoted variable?
Sponsored Links
    #5  
Old 07-09-2008
Registered User
 
Join Date: Apr 2008
Location: Hyderabad, India
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
It does work for me...

Here's the file output
bash-2.05b$ cat file1
/home/hemanth/*.txt

...and here are my commands...
bash-2.05b$ DDPATH=`cat file1`
bash-2.05b$ echo "$DDPATH"
/home/hemanth/*.txt

Send me your output so that I can check.
Sponsored Links
    #6  
Old 07-09-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Location: Out running a Marathon.
Posts: 2,191
Thanks: 48
Thanked 127 Times in 119 Posts
Hammer & Screwdriver The wildcard is doing the substitution

See the following example:


Code:
> cat file1
/home/jg/tmp/file_lookup/*.dat
> echo "$DDPATH"
/home/jg/tmp/file_lookup/*.dat
> echo $DDPATH
/home/jg/tmp/file_lookup/sample.dat
> echo /home/jg/tmp/file_lookup/*.dat
/home/jg/tmp/file_lookup/sample.dat
>

So, try putting your variable with the echo inside quotes. echo "$DDPATH"

This is the same as typing the following:

Code:
>vi *.dat

Which would sequentially open for editing every .dat file you have.
Sponsored Links
    #7  
Old 07-09-2008
Registered User
 
Join Date: Jul 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
cat

yes if we do echo "$DPATH" it gives proper result. but when i want to use this variable for another use like as below -


Code:
for f in "$DPATH" `find -type f`;
do
processLine 
done

it give wrong result like it cant read file with *.mk in the folder.
BR
shailesh

Last edited by radoulov; 07-10-2008 at 04:35 AM.. Reason: please use code tags
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
redirect frintf to a variable robo Shell Programming and Scripting 8 09-27-2011 07:32 PM
Redirect to a Variable? Or is it cmd cap? oxoxo UNIX for Dummies Questions & Answers 2 11-22-2008 07:59 AM
after grep i want to redirect it to some variable mail2sant Shell Programming and Scripting 2 04-07-2008 09:26 AM
Redirect to variable MrAd UNIX for Dummies Questions & Answers 2 05-07-2007 04:18 PM
please help: how to redirect input into a variable artur80 Shell Programming and Scripting 2 11-17-2002 09:18 AM



All times are GMT -4. The time now is 12:09 PM.