473,673 Members | 2,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bash Process Substitution

17 New Member
In this sequence at the command prompt
Expand|Select|Wrap|Line Numbers
  1. $ x=()
  2. $ { while read;  do  x+=("$REPLY"); done; } <<<"$(ls)"
  3. $ printf 'count=%d\n' ${#x[@]}
  4. count=432
  5. $ wc -l <(ls)
  6.      432 /dev/fd/63
  7. $ { while read;  do  x+=("$REPLY"); done; } <(ls)
  8. -bash: syntax error near unexpected token `<(ls)'
  9.  
what causes the error noted?

Doing
Expand|Select|Wrap|Line Numbers
  1. $ x=()
  2. $ ls | { while read; do x+=("$REPLY"); done }
  3. $  printf 'count=%d\n' ${#x[@]}
  4. count=0
  5. $
  6. $
runs without error, but executes the loop in a subprocess, losing the results on termination
BASH 3.2.57(1)-release on OS X 10.10.5
Feb 28 '16 #1
1 4752
numberwhun
3,509 Recognized Expert Moderator Specialist
Have you tried adding a $ before the (ls), like so:

Expand|Select|Wrap|Line Numbers
  1. { while read;  do  x+=("$REPLY"); done; } < $(ls)
  2.  
May 23 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3487
by: Bernhard Kuemel | last post by:
Hi! To relief the problems of accessing a unix machine from behind a restrictive firewall or from an internet cafe I started to make a PHP web interface to bash. I'd like to hear your opinions and advice about my concept, especially regarding security. There is already such a thing (http://www.rohitab.com/cgiscripts/cgitelnet.html). However, it lacks interactive input to programs. To fix this I'd use a frame
6
1764
by: Lukas Holcik | last post by:
Hi Python crazies!:)) There is a problem to be solved. I have a text and I have to parse it using a lot of regular expressions. In (lin)u(ni)x I could write in bash: cat file | sed 's/../../' | sed 's/../../' .. .. .. > parsed_file I write a parser in python and what I must do is: regexp = re.compile(..)
1
7902
by: Goblin | last post by:
Hello i have a little code for updating somethink in my SQL database. I get the error: bash: /root/remstats.pl: /usr/bin/perl: bad interpreter: Permission denied Can someone tell me what's wrong? Or how i can fix that? Greets, Bert The code of the script: #!/usr/bin/perl
1
11629
by: Panagiotis | last post by:
Hi everyone, this is what I want to do in C#: 1) start a Cygwin Bash Shell 2) send the Shell a command, for example "ls -l" 3) capture all the output of the command The code below seems to work when I there isn't alot of output to capture, but when the output increases, the code will freeze.
3
2767
by: kneielj | last post by:
How does the shell interpret command substitution ? if its a normal command, the shell would spawn a child process and the parent would wait for the child to execute and would then collect its exit status. if it is a backgroundprocess, then the parent woul not wait on the child. in similar context, how would command substitution be executed by the shell ?
0
1499
by: lokeshrajoria | last post by:
Hello Everyone, Please go through this script code . this script files executing in bash 2.05 version without mentioning sh. That means if I type simple in command prompt : $moverds.sh then it is execution without any problem and when I try to execute by type in command prompt like: $sh moverds.sh then its giving the following Error root@aramco2.temp.com # sh moverds.sh
4
3573
by: melmack3 | last post by:
Hello My PHP script executes many bash/cmd commands. Functions like "exec()" or "system()" cause that new bash/cmd session is started, the command is executed and the session is closed. Unfortunately it is very slow process so I would like to increase performance and open one bash/cmd session on the begin of my script and execute the commands such as in normal system opened bash/cmd window and close it
3
3639
by: Karim Bernardet | last post by:
Hi I am using pexpect to do ssh tunneling and to open a vnc server (jobs on a grid cluster). When the job is canceled, these 2 processes remain on the worker node (they are detached), so I have to kill them (using a trap command in the bash script of the job) but I need the pid of each process. I have tried to get it like this ssh_tunnel = pexpect.spawn (tunnel_command % globals()) ....
1
2986
by: Gros Bedo | last post by:
Yes I've seen that each python script calls its own instance of Python. Buthow to know which is the good one in bash ? Is there a command that gets the parameters of process, so I could use grep to select the one containing the name of my script ? _________________________________________________________________ Votre contact a choisi Hotmail, l'e-mail nouvelle génération. Créezun compte. http://www.windowslive.fr/hotmail/default.asp
0
2011
by: norseman | last post by:
Gros Bedo wrote: ============================== Yes. man ps explains try ps -AFL | grep then kill -9 found (check it more than twice) 1) If your script is known to hang use what another wrote: py s.py tokens & capture=$! (get the PID ready)
0
8509
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8953
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8855
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8652
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8704
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7487
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2853
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.