LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash scripting problem (https://www.linuxquestions.org/questions/programming-9/bash-scripting-problem-48973/)

raven 03-09-2003 12:33 PM

bash scripting problem
 
hello

if I am typing this into the shell:

for names in $(ls *); do cat ./$names ; done

I always get an error telling me that the files "ls *" finds, are not existing. if I substitute "cat" with "echo" I get the names printed on the screen as it shoud be.

why isnt this working with "cat" for exapmle? tar also doesnt work here.

what did I do wrong?

thanks

raven

Ztyx 03-09-2003 01:46 PM

Strange. Your line works for me (Bash version 2.05b.0(1)).

You could aswell run:
# for names in $(ls); do cat "./$names" ; done

Does the shell command above work?

JStew 03-09-2003 03:23 PM

maybe your 'cat' is an alias of some strange form of echo and options...

raven 03-10-2003 10:54 AM

to Ztyx:

well i tried your line, and it just wont do what I want it to do. I have bash version 2.05.0(1)

to JStew:

actually i found two versions of cat on my system, and none of them seemed to me like an alias (i didnt define any) or a link. strangely, both seem to do the same thing, but one is 9k big, the other one 122k (!!!) bothe print the same version, and both dont work.

any idea?

thanks

raven

crabboy 03-10-2003 12:11 PM

Make sure you don't have any subdirectories. The ls * lists the files in the first level of the subdirs and the cat ./$names will fail.

You may try somthing like this:

Code:

for i in `ls`; do
  if [ -f $i ]; then
    echo $i
  fi
done


raven 03-10-2003 01:25 PM

thanks, it works now fine.

raven

JStew 03-10-2003 05:22 PM

raven: that 'cat' thing (bytes) is weird eh?

raven 03-10-2003 05:48 PM

well. sort of weird :-)

i recompiled the textutils package just for fun and the executable that turned out to be some 30k big... :-) ah well, it works for now :-P

thanks for everything guys

g, raven


All times are GMT -5. The time now is 04:01 PM.