The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find cmd not working as expected Vishal123 Shell Programming and Scripting 6 08-28-2007 11:11 PM
#/usr/bin/csh -f not working as expected? effigy Shell Programming and Scripting 4 06-05-2006 02:00 PM
Var substitution in awk - not working as expected videsh77 Shell Programming and Scripting 3 01-13-2006 10:57 AM
awk not working as expected with BIG files ... videsh77 Shell Programming and Scripting 1 02-24-2005 01:15 PM
which not working as expected osee Shell Programming and Scripting 2 09-07-2004 08:37 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-02-2005
Registered User
 

Join Date: Jul 2005
Posts: 45
ls not working as expected within ksh

Hi,
I use the command

ls a\b\c\*.txt

from the command line on HP UNIX and it works fine - It lists all files matching *.txt in the a\b\c directory

When embeded in a ksh script

`ls a\b\c\*.txt`

it does not work - I get *.txt not found (even though there are files)

I tried variations like having escape / and such but no use.

Please help. Thanks much.

GNMIKE
Reply With Quote
Forum Sponsor
  #2  
Old 07-02-2005
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
For a start, your slashes are the wrong way round, but I'll assume that's a typo

Anyway, having

`ls /foo/bar/*.txt`

will result in a lot of "not found" errors. This is not the way to use command substitution.

my_variable=`ls /foo/bar/*.txt` will work fine.

In your script, just use
ls /foo/bar/*.txt
and it should work fine.

If you're still having problems, please post your entire script.

Cheers
ZB
Reply With Quote
  #3  
Old 07-02-2005
Registered User
 

Join Date: Jul 2005
Posts: 45
Hi,
Thanks for your help - Here is a part of my script...

datapath would have the valye a/b/c
datapatrn would have the value /*.txt (I tried /\*.txt also)
batchsize would have a number such as 2 for example
the result should go to a file $fileslst

`ls -F1rt "$datapath" "$datafilepatrn"|head -"$batchsize">"$fileslist"`

thanks again for your help
Reply With Quote
  #4  
Old 07-02-2005
RishiPahuja's Avatar
Registered User
 

Join Date: Apr 2005
Location: Bangalore, India
Posts: 203
Thumbs up

Quote:
Originally Posted by GNMIKE
Hi,
Thanks for your help - Here is a part of my script...

datapath would have the valye a/b/c
datapatrn would have the value /*.txt (I tried /\*.txt also)
batchsize would have a number such as 2 for example
the result should go to a file $fileslst

`ls -F1rt "$datapath" "$datafilepatrn"|head -"$batchsize">"$fileslist"`

thanks again for your help
The flaw is if you run inside the directory where a is located it will execute, but if you run script through some other direcotry then it will not be able to find the a/b/c path iteself.

Code:
use something like
datapath=$source_dir/a/b/c
datafilepatern='*.txt'

ls -F1rt $datapath/$datafilepattern | head -"$batchsize">"$fileslist"
Reply With Quote
  #5  
Old 07-02-2005
Registered User
 

Join Date: Jul 2005
Posts: 45
Hi,
I see your point but the problem is the same. I get *.txt not found!
Reply With Quote
  #6  
Old 07-03-2005
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Change
`ls -F1rt "$datapath" "$datafilepatrn"|head -"$batchsize">"$fileslist"`
to
ls -F1rt "$datapath$datafilepatrn"|head -"$batchsize">"$fileslist"

i.e. remove the backticks, and remove the space.

Can't guarantee anything without seeing the rest of your script, but if my hunch is correct - that'll fix it.

Cheers
ZB
Reply With Quote
  #7  
Old 07-06-2005
Registered User
 

Join Date: Jul 2005
Posts: 45
I tried this but it still does not work...


#!/usr/bin/ksh
set -x
datapath=/home/oracle/APPS/mobilydw/na/source/gsm/
datafilepatrn="*.txt"

fileslist=/home/oracle/APPS/mobilydw/na/bin/

ls -F1rt "$datapath""$datafilepatrn"|head -10>"$fileslist"

exit
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:52 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0