The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
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
Redirect Output In Variable ZINGARO UNIX for Dummies Questions & Answers 1 08-02-2006 06:56 AM
Redirect from Variable to command line?? ugh UNIX for Dummies Questions & Answers 8 03-28-2006 10:31 AM
please help: how to redirect input into a variable artur80 Shell Programming and Scripting 2 11-17-2002 10:18 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-09-2008
shailesh_arya shailesh_arya is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 20
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
  #2 (permalink)  
Old 07-09-2008
phemanth24 phemanth24 is offline
Registered User
  
 

Join Date: Apr 2008
Location: Hyderabad, India
Posts: 14
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
  #3 (permalink)  
Old 07-09-2008
shailesh_arya shailesh_arya is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 20
cat

oops not working...


also i want to use this variable further in my script
BR
shailesh
  #4 (permalink)  
Old 07-09-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
What shell? Could you post the output that demonstrates expansion of the * with quoted variable?
  #5 (permalink)  
Old 07-09-2008
phemanth24 phemanth24 is offline
Registered User
  
 

Join Date: Apr 2008
Location: Hyderabad, India
Posts: 14
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.
  #6 (permalink)  
Old 07-09-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink 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.
  #7 (permalink)  
Old 07-09-2008
shailesh_arya shailesh_arya is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 20
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:43 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0