LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-09-2003, 01:33 PM   #1
raven
Member
 
Registered: Dec 2001
Location: Basel, Switzerland
Distribution: ubuntu
Posts: 297

Rep: Reputation: 31
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
 
Old 03-09-2003, 02:46 PM   #2
Ztyx
Member
 
Registered: Dec 2001
Location: Stockholm, Sweden
Distribution: Ubuntu, Kubuntu and Debian
Posts: 338

Rep: Reputation: 30
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?
 
Old 03-09-2003, 04:23 PM   #3
JStew
Member
 
Registered: Oct 2002
Location: North Atlanta
Distribution: LFS
Posts: 229

Rep: Reputation: 30
maybe your 'cat' is an alias of some strange form of echo and options...
 
Old 03-10-2003, 11:54 AM   #4
raven
Member
 
Registered: Dec 2001
Location: Basel, Switzerland
Distribution: ubuntu
Posts: 297

Original Poster
Rep: Reputation: 31
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
 
Old 03-10-2003, 01:11 PM   #5
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
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
 
Old 03-10-2003, 02:25 PM   #6
raven
Member
 
Registered: Dec 2001
Location: Basel, Switzerland
Distribution: ubuntu
Posts: 297

Original Poster
Rep: Reputation: 31
thanks, it works now fine.

raven
 
Old 03-10-2003, 06:22 PM   #7
JStew
Member
 
Registered: Oct 2002
Location: North Atlanta
Distribution: LFS
Posts: 229

Rep: Reputation: 30
raven: that 'cat' thing (bytes) is weird eh?
 
Old 03-10-2003, 06:48 PM   #8
raven
Member
 
Registered: Dec 2001
Location: Basel, Switzerland
Distribution: ubuntu
Posts: 297

Original Poster
Rep: Reputation: 31
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash scripting problem (bug?) zz9pluralzalpha Linux - Software 2 04-12-2005 02:51 PM
bash scripting problem sutley Linux - Software 1 12-17-2004 12:33 PM
bash scripting problem Sammy2ooo Linux - General 3 12-13-2004 01:31 PM
BASH Scripting Design Problem... amaze Linux - General 1 08-19-2003 09:30 AM
BASH scripting problem deadlock Programming 5 08-15-2003 05:33 AM


All times are GMT -5. The time now is 06:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration