Path: utzoo!utgpu!watmath!att!pacbell!sactoh0!tree!stever From: stever@tree.UUCP (Steve Rudek) Newsgroups: comp.unix.questions Subject: sed behaves differently when run in backquotes/subshell Keywords: `sed`, sh, microport_system_V/AT Message-ID: <350@tree.UUCP> Date: 6 Aug 89 20:06:51 GMT Organization: TREE BBS (916)-349-0385 Sacramento, Ca Lines: 45 I needed a shell script which would take strings of letters and alphabetize them into a single line and sed + sort seemed like the best choice. But I find that sed performs differently when part of a pipeline not explicitly in a subshell than it does when run in backquotes. What's the problem? Given a file ".TST" containing: e s m l o09 ux123 35 y8 anrt467 iwhp5z h and the following script: DATA_DIR=.TST #----------------------------# echo "exploding and alphabetizing without subshell works fine" cat .TST | sed 's/\(.\)/\1\ /g'|sort|paste -s -d"\0" - #----------------------------# echo "can't explode the strings when the same pipeline is run in backquotes" GUESSES=`cat .TST | sed 's/\(.\)/\1\ /g'|sort|paste -s -d"\0" -` echo "GUESSES==$GUESSES" I get the output: exploding and alphabetizing without subshell works fine 012334556789aehhilmnoprstuwxyz can't explode the strings when the same pipeline is run in backquotes GUESSES==35anrt467ehiwhp5zlmo09sux123y8 What is happening here is that strings such as "abc" are being properly split into a b c in the first case while they pass through unchanged in the second case. -- ---------- Steve Rudek {ucbvax!ucdavis!csusac OR ames!pacbell!sactoh0} !tree!stever