LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-29-2010, 01:15 AM   #1
anu_1
LQ Newbie
 
Registered: Jan 2010
Posts: 12

Rep: Reputation: 0
File Read


In Linux
test=$(echo -1| read a1;echo $a1)
Could anyone help ...when I give echo $test it prints nothing...in aix it works fine

Thanks for help
 
Old 01-29-2010, 01:32 AM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
I have no idea how the AIX shell handles this, so I can't comment on that.

The problem has to do with the way that the processes in pipes communicate. Each process in a pice statement spawns a proper subshell, and we all know that variables will live only inside the shell instance they are declared (maybe in AIX they all are global? no real idea). In your case, the read command is spawning a new shell to run, which effectively means that whatever variable it sets after reading a string will be vaporized as soon as the read shell is closed, and hence it will not be visible to the next echo.

A solution would be to run both in the same subshell

Code:
$ echo foo | (read bar && echo $bar)
foo

Last edited by i92guboj; 01-29-2010 at 01:33 AM. Reason: typo
 
  


Reply



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
Read Only File System? Can't read superblock! haughjd Linux - Software 4 01-15-2008 08:27 AM
web server (fedora core 5) became read-only file system after i upload a file nggs8411 Linux - Server 1 03-26-2007 09:23 AM
Java File Processing using Scanner; Can't get it to read file in running directory xemous Programming 2 09-26-2006 06:13 PM
how do I make a read-only file NOT read-only? robster Linux - General 1 02-17-2004 09:11 PM
Change from Read only to Read Write File System? justiceisblind Linux - Newbie 3 03-03-2002 07:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:14 PM.

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
Open Source Consulting | Domain Registration