Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 01-29-2010, 02:15 AM   #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 aix it works fine

Thanks for help
Old 01-29-2010, 02:32 AM   #2
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

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

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


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

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

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