Re: Process substitution gives error in script



On Jan 4, 1:45 am, Stephane CHAZELAS <stephane_chaze...@xxxxxxxx>
wrote:

Process substitution is piping and spawns a subshell as well.
In foo | bar, which end of the pipe is in a subshell or not
depends on the shell.

Consider this: I want to analyze the output of a command, say, ls.
AFAIU, I can do either

ls |
while read line; do
# some test on $line fails
exit
done

OR

while read line; do
# some test on $line fails
exit
done < <(ls)

OR

ls > ls.output
while read line; do
# some test on $line fails
exit
done <ls.output

Speaking about portability: first one is highly intuitive. But where
the exit command runs depends on how shell implements piping, and
hence is not portable. Second one is not portable either for the
process-substitution; but the exit command sure runs on the main
script. So does it mean that all scripts that make use of piping and
process-substitution are not portable?

Third one, probably yes. But I don't see any performance gain across
the scripts. All of them incur running another program and reading its
output.

Given that I have a "#!/bin/bash" as the first line, and all bash
versions are consistent in implementation, isn't my script portable
enough? I'm not sure if I understand the true meaning of portability.

:-j
.



Relevant Pages

  • PATCH [1/3]: Replace kernel/timeconst.pl with kernel/timeconst.sh (v2)
    ... The new shell script ... It requires a shell which can do 64 bit math, such as bash, busybox ash, ... makefile so script is responsible for creating output file, ... +trap "rm $FILENAME" EXIT ...
    (Linux-Kernel)
  • Re: Changing directories, script, mc
    ... shell, it doesn't need to be executable. ... $chap1 konsole exits immediately ... appeared in the script, that would be what was doing it - you wouldn't ... would exit. ...
    (comp.os.linux)
  • Re: Errors when reading a file in Bourne shell -- HELP
    ... I am trying to exit out of the ... the do while and not the shell itself. ... whole shell script. ... to 1 and checking it after the loop. ...
    (comp.unix.questions)
  • Re: any tips for this script
    ... currently able to execute your script, ... advantage of builtin features of any modern shell that can substitute ... solution is to process your script with the free autoconfig GNU utility, ... it is written with portability in mind ...
    (comp.unix.shell)
  • Re: [opensuse] Lazarus and free pascal need ELF
    ... In a bourne shell interpreter, which is what you are in while you are logged in and sitting at a command prompt, the syntax "dot space filename" does not execute the file, it sources the file. ... It has the effect that your current shell instance ends up directly executing the commands, which may look and smell like the normal way a script or program is executed, but it's in fact quite different. ... The simplest example of why this is "wrong" even though it seems to "work for scripts" would be to look at any typical script that has an exit command. ...
    (SuSE)