file of filenames, trying to execute %> cat filename

file of filenames, trying to execute %> cat filename

Post by Sean Cho » Fri, 29 Jun 2001 05:47:53



this is not my ultimate goal, but I thought I should test this before
writing the full script.

I have a file of filenames.
file1:
dog
cat
fish

not I want to execute the following script;
I can't figure out why I cannot get the script to run without the error
message

the script:
1  #!/bin/sh
2
3  prefix="~/tempdir"
4
5  for filename in `cat dfiles`
6  do
7      TARGETFILE="$prefix/`echo $filename | sed 's/.*\/\([^\/]*$\)/\1/'`"
8      echo $TARGETFILE
9      cat $TARGETFILE
10 done

only line 10 seems to be the problem

the error message:
[schoi_d11776b] % compfiles
~/tempdir/dog
cat: cannot open ~/tempdir/dog
~/tempdir/cat
cat: cannot open ~/tempdir/fish
~/tempdir/cat
cat: cannot open ~/tempdir/fish
[schoi_d11776b] %

the strange thing is that I am able to perform
%> cat ~/tempdir/dog
on the command line just fine; it just doesn't like executing the
command in the script

ls -l for the file and directory says
drwxrwxrwx - for directory
-rwxrwxrwx - for the files

would appreciate your insights as to what i'm doing wrong

thanks
Sean

 
 
 

file of filenames, trying to execute %> cat filename

Post by Charles Dem » Fri, 29 Jun 2001 06:11:14




Quote:>this is not my ultimate goal, but I thought I should test this before
>writing the full script.

>I have a file of filenames.
>file1:
>dog
>cat
>fish

>not I want to execute the following script;
>I can't figure out why I cannot get the script to run without the error
>message

>the script:
>1  #!/bin/sh
>2
>3  prefix="~/tempdir"

try this:

eval prefix="~/tempdir"

IIRC, it's a question of when the tilde gets expanded.

Chuck Demas

- Show quoted text -

Quote:>4
>5  for filename in `cat dfiles`
>6  do
>7      TARGETFILE="$prefix/`echo $filename | sed 's/.*\/\([^\/]*$\)/\1/'`"
>8      echo $TARGETFILE
>9      cat $TARGETFILE
>10 done

>only line 10 seems to be the problem

>the error message:
>[schoi_d11776b] % compfiles
>~/tempdir/dog
>cat: cannot open ~/tempdir/dog
>~/tempdir/cat
>cat: cannot open ~/tempdir/fish
>~/tempdir/cat
>cat: cannot open ~/tempdir/fish
>[schoi_d11776b] %

>the strange thing is that I am able to perform
>%> cat ~/tempdir/dog
>on the command line just fine; it just doesn't like executing the
>command in the script

>ls -l for the file and directory says
>drwxrwxrwx - for directory
>-rwxrwxrwx - for the files

>would appreciate your insights as to what i'm doing wrong

>thanks
>Sean

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.


 
 
 

file of filenames, trying to execute %> cat filename

Post by Chris F.A. Johnso » Fri, 29 Jun 2001 06:53:36



> this is not my ultimate goal, but I thought I should test this before
> writing the full script.

Exactly the way to go about it!
And conversely, the way to debug a script is to test each part separately,
i.e. find the smallest section of code that will reproduce the error.

Quote:> I have a file of filenames.
> file1:
> dog
> cat
> fish

> not I want to execute the following script;
> I can't figure out why I cannot get the script to run without the error
> message

> the script:
> 1  #!/bin/sh
> 2
> 3  prefix="~/tempdir"

How does your version of /bin/sh handle tilde expansion?

Try leaving out the quotation marks:
        prefix=~/tempdir

Or you could use $HOME/tempdir instead.

- Show quoted text -

Quote:> 4
> 5  for filename in `cat dfiles`
> 6  do
> 7      TARGETFILE="$prefix/`echo $filename | sed 's/.*\/\([^\/]*$\)/\1/'`"
> 8      echo $TARGETFILE
> 9      cat $TARGETFILE
> 10 done

> only line 10 seems to be the problem

> the error message:
> [schoi_d11776b] % compfiles
> ~/tempdir/dog
> cat: cannot open ~/tempdir/dog
> ~/tempdir/cat
> cat: cannot open ~/tempdir/fish
> ~/tempdir/cat
> cat: cannot open ~/tempdir/fish
> [schoi_d11776b] %

> the strange thing is that I am able to perform
> %> cat ~/tempdir/dog
> on the command line just fine; it just doesn't like executing the
> command in the script

> ls -l for the file and directory says
> drwxrwxrwx - for directory
> -rwxrwxrwx - for the files

> would appreciate your insights as to what i'm doing wrong

> thanks
> Sean

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2001, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License
 
 
 

file of filenames, trying to execute %> cat filename

Post by Sean Cho » Fri, 29 Jun 2001 07:23:34


of the suggestions I received, this was the one that worked
prefix="$HOME/tempdir"

prefix=~/tempdir
and
eval prefix="~/tempdir"

did not work

thanks for your help

Sean



> > this is not my ultimate goal, but I thought I should test this before
> > writing the full script.

> Exactly the way to go about it!
> And conversely, the way to debug a script is to test each part separately,
> i.e. find the smallest section of code that will reproduce the error.

> > I have a file of filenames.
> > file1:
> > dog
> > cat
> > fish

> > not I want to execute the following script;
> > I can't figure out why I cannot get the script to run without the error
> > message

> > the script:
> > 1  #!/bin/sh
> > 2
> > 3  prefix="~/tempdir"

> How does your version of /bin/sh handle tilde expansion?

> Try leaving out the quotation marks:
>    prefix=~/tempdir

> Or you could use $HOME/tempdir instead.

> > 4
> > 5  for filename in `cat dfiles`
> > 6  do
> > 7      TARGETFILE="$prefix/`echo $filename | sed 's/.*\/\([^\/]*$\)/\1/'`"
> > 8      echo $TARGETFILE
> > 9      cat $TARGETFILE
> > 10 done

> > only line 10 seems to be the problem

> > the error message:
> > [schoi_d11776b] % compfiles
> > ~/tempdir/dog
> > cat: cannot open ~/tempdir/dog
> > ~/tempdir/cat
> > cat: cannot open ~/tempdir/fish
> > ~/tempdir/cat
> > cat: cannot open ~/tempdir/fish
> > [schoi_d11776b] %

> > the strange thing is that I am able to perform
> > %> cat ~/tempdir/dog
> > on the command line just fine; it just doesn't like executing the
> > command in the script

> > ls -l for the file and directory says
> > drwxrwxrwx - for directory
> > -rwxrwxrwx - for the files

> > would appreciate your insights as to what i'm doing wrong

> > thanks
> > Sean

> --
>     Chris F.A. Johnson                        http://cfaj.freeshell.org
>     ===================================================================
>     My code (if any) in this post is copyright 2001, Chris F.A. Johnson
>     and may be copied under the terms of the GNU General Public License

Sean Choi
Duke University School Engineering
Class of 2000
 
 
 

file of filenames, trying to execute %> cat filename

Post by Bill Marcu » Sat, 30 Jun 2001 00:14:34



>of the suggestions I received, this was the one that worked
>prefix="$HOME/tempdir"

>prefix=~/tempdir
>and
>eval prefix="~/tempdir"

>did not work

This works from the command line, but not in a script that begins with
#!/bin/sh; are you sure that your login shell is /bin/sh and not bash or
ksh?
 
 
 

1. a file of filenames compared to another file of filenames

I have 2 files, each containing file names.

let's say this is file 1:
wolf
lion
shark

let's say this is file 2:
dog
cat
fish

I'm trying to do a diff between corresponding filesnames. In other words
%> diff wolf dog
%> diff lion cat
%> diff shark fish

instead of executing diff for each comparison, how can I do this with an
unix shell script?

Thanks,
Sean

2. gateway firewall problems

3. renaming files from filename to filename-date

4. How do you mount a FAT(PC/DOS) hard disk under Solarix x86?

5. cat filename >/dev/what.device

6. Linux Server Win95 client

7. cat filename > [termserver printer] ?

8. IRC.. behind firewall

9. cat filename >/dev/lp1 ?

10. can only print by cat filename > /dev/lp1

11. Read filename from file & execute on it?

12. ld: fatal: file <filename>: cannot msync file; errno=12 on 2.5

13. Read filename from file & execute on it?