If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > shell scripting problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-19-03, 06:28
gjs123 gjs123 is offline
Registered User
 
Join Date: Dec 2003
Posts: 1
shell scripting problem

I have a procedure that creates two files only one of theses files is created at a time depending on if there was an error or not, what I need to do is to search a specified directory and pickup the name of the file that is in there and then be able to store this a a variable so that the script can then just pass in the variable to see which script to run next.

I have tried something like this

#!/bin/bash

for file in 'ls /u01/dev/oracle/blake/procedures/sales/*.sh'; do
echo $file
done

###########

but all i get returned is

'ls /u01/dev/oracle/blake/procedures/sales/<filename>.sh'

All I need returned is just the filename.

Many thanks in advance
Reply With Quote
  #2 (permalink)  
Old 12-19-03, 12:06
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Look here...

rename files in script
Reply With Quote
  #3 (permalink)  
Old 12-20-03, 13:53
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
Hello gjs123,
I get the same message when the path is not correctly or the file does not exist . If the path and the named files exist, your script will work. Please check the pathname and the existing files named in your wildcards.
__________________
Greetings from germany
Peter F.
Reply With Quote
  #4 (permalink)  
Old 12-20-03, 18:31
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
The problem is because your ls command is within single quotes. You are attempting to do this exercise using command substitution and the syntax for that is $(command) or `command` (note the `` backticks are not quotes).

This is NOT the best way to perfom this exercise IMHO. You should take advantage of filename expansion through globbing.

e.g.

for filename in * ; do ...

rather than

for filename in $(ls *); do ...

Read the thread I posted and all will become clear ;-)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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