Turn off subshelling of pipe

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Turn off subshelling of pipe
# 1  
Old 05-18-2009
Turn off subshelling of pipe

After searching the forum, I found that Bash spawns a subshell when using the pipe. I am wondering if there is an option or any other way to turn off this fuctionality.

We are pulling over some scripts from a Korn shell environment. I have found ways to work around looping from a pipe (Thanks to this forum!!), but we would like to not change this logic. We tried to invoke the korn shell (#!/bin/ksh93) environment but found that this version is old and unacceptable.

Any Ideas? Is there a switch or setting?

Thanks!
# 2  
Old 05-19-2009
Please post an example code.
# 3  
Old 05-19-2009
ls -1 2>/dev/null | while read LAND_FILE
do
...code
done

This spawns a subshell.

while read LAND_FILE <(ls -1 2>/dev/null)
do
...code
done

This doesn't spawn a subshell.

We would like to be able to run the first loop without spawning a sub-shell.

Thanks in advance
# 4  
Old 05-20-2009
Quote:
Originally Posted by jryan
[...]We are pulling over some scripts from a Korn shell environment. I have found ways to work around looping from a pipe (Thanks to this forum!!), but we would like to not change this logic.
Just to clarify,
why you don't want to use process substitution (the <(...) syntax)?

Quote:
We tried to invoke the korn shell (#!/bin/ksh93) environment but found that this version is old and unacceptable.
Old? KSH-93 is the most recent version of the KornShel Language. It is also most feature-rich implementation of the KornShell. It's currently maintained and continuously improved by its creator David Korn and others at AT&T.

Quote:
Any Ideas? Is there a switch or setting?
Consider that ksh93 is different from the other shells as far as the last command in a pipeline is concerned (it does not fork a subshell), just like you want it to be.
Consider the following:
Code:
zsh-4.3.9-dev-2[t]% bash -c 'echo OK|while read;do ok=$REPLY;done;echo $ok'

zsh-4.3.9-dev-2[t]% pdksh -c 'echo OK|while read;do ok=$REPLY;done;echo $ok'

zsh-4.3.9-dev-2[t]% ksh93 -c 'echo OK|while read;do ok=$REPLY;done;echo $ok'
OK

The Z-Shell behaves in the same way (as ksh93).

You may change this by enclosing the loop and all the following commands with braces for example:

Code:
zsh-4.3.9-dev-2[t]% bash -c 'echo OK|{ while read;do ok=$REPLY;done;echo $ok;}'
OK
zsh-4.3.9-dev-2[t]% pdksh -c 'echo OK|{ while read;do ok=$REPLY;done;echo $ok;}'
OK

Hope this helps.
# 5  
Old 09-02-2009
>ls -1 2>/dev/null | while read LAND_FILE
>do
>...code
>done


following is what you could do to work around the subshelling:

while read LAND_FILE
do
...code
done <<EOF
`ls -1 2>/dev/null`
EOF
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Just can't turn off ipv6?

I'm running a Linux OS that uses Debian as it's base. A commercial vpn is installed that uses OpenVPN. For some reason, I can't get ipv6 to tunnel properly .... and Ipleak.net shows that my location is being unmasked by ipv6. I've tried kernel commands at boot, I've tried sysctl.conf commands.... (2 Replies)
Discussion started by: benc
2 Replies

2. UNIX for Dummies Questions & Answers

Turn off logging while doing LFTP

Hello All, Is there a way to turn off the caching of the login/password details in ~/.lftp/transfer_log file when i do lftp to remote site. we are using Red Hat Linux OS /usr/bin/lftp<<-ftp_script open sftp://$FTPHOST user $FTPUSER $FTPPASS lcd /tmp/TEST_Data put "test.gpg" bye ftp_script ... (0 Replies)
Discussion started by: Ariean
0 Replies

3. Shell Programming and Scripting

How to ignore Pipe in Pipe delimited file?

Hi guys, I need to know how i can ignore Pipe '|' if Pipe is coming as a column in Pipe delimited file for eg: file 1: xx|yy|"xyz|zzz"|zzz|12... using below awk command awk 'BEGIN {FS=OFS="|" } print $3 i would get xyz But i want as : xyz|zzz to consider as whole column... (13 Replies)
Discussion started by: rohit_shinez
13 Replies

4. Shell Programming and Scripting

turn list into one line

Hi All i am cat'ing a file and then using cut to get rid of some info, is there a way to turn the list into one line i.e 1 2 3 4 5 into 1 2 3 4 5 (4 Replies)
Discussion started by: ab52
4 Replies

5. Shell Programming and Scripting

Replace pipe with Broken Pipe

Hi All , Is there any way to replace the pipe ( | ) with the broken pipe (0xA6) in unix (1 Reply)
Discussion started by: saj
1 Replies

6. Programming

How to turn argv[1] into a string in C?

i have a function that's parameter is char *s and in the main function i am sending that function &(argv), but i dont think this is working, how can i fix this? can i cast it to be a string or something? is there a way i can create a new string thats exactly what argv is equal to... (6 Replies)
Discussion started by: omega666
6 Replies

7. UNIX for Dummies Questions & Answers

turn off sound

how to disable anoying beep sound??? (4 Replies)
Discussion started by: nnn
4 Replies

8. UNIX for Dummies Questions & Answers

How to turn off duplex

I am using digital Unix and lpd. I have HP 4200n LaserJet TCP printer, but when I use lpr command, it always print duplex. I can turn off duplex feature at the panel of the printer, but then other Windows computer cannot print duplex. How can I set up /etc/printcap file so that it will be... (2 Replies)
Discussion started by: hiepng
2 Replies

9. SuSE

RH8.0 firewall WILL NOT turn off

I have been trying to disable the firewall on a new install of RH8(Psyche). It will NOT stay disabled. I've gone thru system tools, security level and disabled it, and it says YES, like it will save my settings, but when i open it up again, it is always back to HIGH. I also tried using the... (3 Replies)
Discussion started by: kymberm
3 Replies
Login or Register to Ask a Question