Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2003
    Posts
    1

    Unanswered: 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

  2. #2
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525

  3. #3
    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.

  4. #4
    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 ;-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •