Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cat command in unix shell script

Tags:

bash

shell

unix

cat

I have 2 lines of code

1) With the following code:

for i in `ls *.properties`; do cat $i; done

I get the error:

cat: file_name.properties: No such file or directory.

2) On the other hand:

for i in *.properties; do cat $i; done

Works fine!

I thought both were the same. Can someone help me understand the difference between the two? Using bash shell.

like image 451
Win Man Avatar asked May 30 '26 08:05

Win Man


1 Answers

What does the following command print?

cat -v <<< `ls *.properties`

I guess the problem is, that ls is a strange alias, e.g. something like

ls='ls --color'

Edit: I have seen this before. The alias should be: alias ls='ls --color=auto'

like image 83
nosid Avatar answered Jun 01 '26 22:06

nosid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!