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
Find cmd not working as expected Vishal123 Shell Programming and Scripting 6 08-29-2007 03:11 AM
#/usr/bin/csh -f not working as expected? effigy Shell Programming and Scripting 4 06-05-2006 06:00 PM
Var substitution in awk - not working as expected videsh77 Shell Programming and Scripting 3 01-13-2006 01:57 PM
awk not working as expected with BIG files ... videsh77 Shell Programming and Scripting 1 02-24-2005 04:15 PM
which not working as expected osee Shell Programming and Scripting 2 09-07-2004 12:37 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-02-2005
GNMIKE GNMIKE is offline
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
  #2 (permalink)  
Old 07-02-2005
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
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
  #3 (permalink)  
Old 07-02-2005
GNMIKE GNMIKE is offline
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
  #4 (permalink)  
Old 07-02-2005
RishiPahuja's Avatar
RishiPahuja RishiPahuja is offline
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"
  #5 (permalink)  
Old 07-02-2005
GNMIKE GNMIKE is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 45
Hi,
I see your point but the problem is the same. I get *.txt not found!
  #6 (permalink)  
Old 07-03-2005
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
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
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 07:36 PM.


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