Created
September 30, 2012 04:36
-
-
Save couchtim/3805844 to your computer and use it in GitHub Desktop.
Demo of bash/dash subshell when pipe to loop construct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@localhost couchbase-stuff]# cat tmp.sh | |
#! /bin/sh | |
count=0 | |
/bin/ls /etc | while read f; do | |
count=$((count + 1)); | |
echo $count $f; | |
done | |
# This prints 0 in bash and dash; prints count (e.g., 262) in ksh | |
echo "at the end, count is: $count" | |
[root@localhost couchbase-stuff]# sh tmp.sh|tail | |
254 X11 | |
255 xdg | |
256 xinetd.conf | |
257 xinetd.d | |
258 xml | |
259 yp.conf | |
260 yum | |
261 yum.conf | |
262 yum.repos.d | |
at the end, count is: 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment