You are not logged in.

#1 2004-11-16 05:37:29

rasat
Forum Fellow
From: Finland, working in Romania
Registered: 2002-12-27
Posts: 2,293
Website

Strange bash behavior

This is run in two different machines. In machine 1 cat cannot read variables but does in machine 2.

machine 1 wrote:

[root@localhost ~]$ echo "This is a test" >test.tmp
[root@localhost ~]$ TEST=$(cat test.tmp)
[root@localhost ~]$ cat $TEST
cat: This: No such file or directory
cat: is: No such file or directory
cat: a: No such file or directory
cat: test: No such file or directory
[root@localhost ~]$

machine 2 wrote:

[root@zeus /tmp] $ echo "This is a test" >test.tmp
[root@zeus /tmp] $ TEST=$(cat test.tmp)
[root@zeus /tmp] $ echo $TEST
This is a test
[root@zeus /tmp] $


Markku

Offline

#2 2004-11-16 07:03:54

poetofnumbers
Member
From: Kansas, United States
Registered: 2004-10-30
Posts: 106
Website

Re: Strange bash behavior

I don't understand why this is strange.  Here is what I get:

# echo "This is a test" >test.tmp
# TEST=$(cat test.tmp)
# cat $TEST
cat: This: No such file or directory
cat: is: No such file or directory
cat: a: No such file or directory
cat: test: No such file or directory
# echo $TEST
This is a test
# set
...
TEST='This is a test'
...

From what I know $() takes precedence over =

Drew
Knowledge Brings Fear


Sweet, now I can play with myself.

Offline

#3 2004-11-16 07:31:38

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: Strange bash behavior

exactly.
in one you are trying to cat the filename held in the TEST variable.
Since TEST="This is a test", you are trying to cat "this is a test"...
so cat tries to find each of the files

on the second one, you are just echoing the contents of the TEST variable.
seems fine to me.


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#4 2004-11-16 12:16:09

rasat
Forum Fellow
From: Finland, working in Romania
Registered: 2002-12-27
Posts: 2,293
Website

Re: Strange bash behavior

cactus wrote:

on the second one, you are just echoing the contents of the TEST variable.
seems fine to me.

When I received the machine 2's reply, after corresponing about cat, I took for granted machine 2 used cat $TEST not echo $TEST.

Thanks, problem solved.


Markku

Offline

Board footer

Powered by FluxBB