Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

redirect cat to variable

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-09-2008
shailesh_arya shailesh_arya is offline
Registered User
 
Join Date: Jul 2008
Last Activity: 11 July 2008, 12:07 AM EDT
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 Unix and Linux 07-09-2008
phemanth24 phemanth24 is offline
Registered User
 
Join Date: Apr 2008
Last Activity: 6 November 2008, 4:00 AM EST
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 Unix and Linux 07-09-2008
shailesh_arya shailesh_arya is offline
Registered User
 
Join Date: Jul 2008
Last Activity: 11 July 2008, 12:07 AM EDT
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
cat

oops not working...
Linux

also i want to use this variable further in my script
BR
shailesh
    #4  
Old Unix and Linux 07-09-2008
radoulov's Unix or Linux Image
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 23 April 2015, 3:05 PM EDT
Location: Варна, България / Milano, Italia
Posts: 5,690
Thanks: 184
Thanked 626 Times in 584 Posts
What shell? Could you post the output that demonstrates expansion of the * with quoted variable?
Sponsored Links
    #5  
Old Unix and Linux 07-09-2008
phemanth24 phemanth24 is offline
Registered User
 
Join Date: Apr 2008
Last Activity: 6 November 2008, 4:00 AM EST
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 Unix and Linux 07-09-2008
joeyg's Unix or Linux Image
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 28 July 2015, 11:10 AM EDT
Location: Within two miles of a Dunkin donuts.
Posts: 2,360
Thanks: 85
Thanked 164 Times in 150 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 Unix and Linux 07-09-2008
shailesh_arya shailesh_arya is offline
Registered User
 
Join Date: Jul 2008
Last Activity: 11 July 2008, 12:07 AM EDT
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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 01:45 AM.