I have been trying to use read in a script with issues so I tried some things on the command line.
and
are only producing any output after being invoked the first time after rebooting the machine. I also got into some state where echo was producing "unbound variable" errors.
Can anyone point me in the right direction?
Mike
PS. This has something to do with subshells but I'm not exactly clear what is going on.
Last edited by Michael Stora; 07-23-2014 at 01:48 PM..
If "some program" were cat, would it change any memory or variables in your current shell? Of course not, it doesn't have access to them -- it's a separate process. All commands run after a pipe, including shell built-ins, have to run in a new process.
So read is run in a brand-new, independent shell, which happily sets the variable x in that shell -- then immediately dies, leaving the original shell unchanged.
Try this:
Here it will work because the read and the echo are grouped in the same shell.
ksh does pipes in the opposite order so "echo | read" will actually work -- but this isn't something you can count on unless you know you have KSH.
It has to, to avoid deadlocks. Which runs first, the echo or the read? Will either of them hang, waiting for the other? Make them independent and it doesn't matter.
That is not because of read, but because the right hand side of the pipe is executed in a subshell in bash and some other bourne type shells. It works in ksh though...
--
Note that IFS=":"; read ..... permanently changes IFS to a colon. To use IFS local to the read command (in bash / ksh93 / zsh ) you can use:
After execution of the command the IFS remains unchanged..
This User Gave Thanks to Scrutinizer For This Post:
Hi,
I am facing issues with the below:
I have a lookup file say lookup.lkp.This lookup.lkp file contains strings delimited by comma(,).
Now i want to read this command from file and execute it.
So my code below is :
Contents in the lookup.lkp file is :
c_e,m,a,`cd $BOX | ls cef_*|tail... (7 Replies)
Hi,
I am currently reading a tar file and searching for a particular word using grep e.g. Plane. At the moment, if a sentence is found with the word "Plane" the sentence itself is piped to another file.
Here is the code i am using;
for jar in 'cat jar_file.tar'; do
tar -tvf... (3 Replies)
Hi.
I want to use the DHCP server that comes with vxWorks 6.4.
The DHCP server implementation has a table that contains addresses of DHCP servers that will receive a copy of all the client requests that the local server gets, thus the server acts as a dhcp relay at the same time.
Can anyone... (4 Replies)
I have been using firefox3.5 now for some months and noticed that some images, notably in the png format, do not display correctly: the images are not displayed at all or display in part whereby the rest of the image shows a black rectangle. Does anybody else suffer from this problem?
Desktop:... (0 Replies)
Hi Guys,
I have this script which is being called from another script,
sh +x SCRIPTNAME.
Now this script is failing saying the source file is missing. But i was able to see the source file was present. It was renamed and but somehow the source file is removed. There is no remove command in the... (1 Reply)
Hello,
basically what this script is supposed to do is showing a list of hosts that is given a number, that you will be able to choose from a list.
A check is made to verify that the chosen number is within the array and this is where things go bad and I don't know why, bizarre.
I've spent... (5 Replies)
Hello!
I have a question about loops and arrays. I'm trying to go through this:
for aa in 01 02 03
OrigNum=$(grep ${Orig} Ba3In2F12.prepos | wc -l)
OrigNum=$((${OrigNum} - 1))
echo ${OrigNum}
etc
It gets stuck on the second line. The error reads:
./asdf: line 30:... (5 Replies)
Hello. I'm getting very odd behavior when I try to change a user's password in Solaris 8. The shell, where it used to ask for a new passwd and a confirmation, now asks FOUR times, with two success message.
This is what happens every time:
# passwd myusername
New Password: xxxxxxxx
New... (2 Replies)
Hey i have a small script in which i check if a file with that pattern exists or not. If present then i go ahead with further processing.
In the present situation i have only one file with that name and for loop is reading twice. Here is the script. And the output of debug mode. Please help.... (5 Replies)
Hi,
I am working on a custom made FTP application. The application is behaving erratically for the "ls" command. Wild card character passed to the "ls" command (like "ls *temp") is giving inconsistent results. On debuggin I have found that the "ls" command is implemented as shown below in the... (7 Replies)