bash - Why does the pre/absence of xargs affect the output from a subsequent echo command? -


bash noob here, curious in behavior of following shell function (designed pack ascifiied hex sequences):

pack() {     sedf=$(extended_sed)               # choose "-r"/"-e" bsd/linux flavors     in=$(sed 's/%//g' <<< "$1")        # allow "%41%41..."     if [ -z $(grep '\\x' <<< "$in") ]  # allow "4142..."              in=$(sed -$sedf 's/(..)/\\\\x\1/g' <<< "$in")     else                               # allow "\x41\x42..."         in=$(sed -$sedf 's/\\/\\\\/g' <<< "$in")     fi     echo "$in" | xargs echo -en        # pack through -e, suppress cr    # testing     echo "$in"                          echo -en "$in"                     # doesn't pack  } 

both pack "\x41\x41" , pack "4141" produce following output:

aa\\x41\\x41 \x41\x41 

but when run echo -e "\\x41\\x41" or echo -e "\x41\x41" command line, outside script, aa, puzzlingly different behavior of these commands when run inside script.

so though it's not problem script, curious - (a) why, inside script, use of xargs leading desired output echo -en? ; , (b) why behavior of non-xargs echo inside script differ outside script, i.e. when run command line?


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -