On 12/16/2013 1:02 PM, Eugene Schulman (BLOOMBERG/ 120 PARK) wrote:
> Hi guys,
> I'm looking for a method to do raw command substitution.
>
> The issue:
> - Need a ksh93t+ / ksh93u facillity to be able to take the literal
> output of a command with no substitutions or omissions, where the
> substitute data is less than 1kB. Target platforms are RHEL 6.4,
> Solaris 11 & AIX 7.1.
>
> Examples. printf is used below for illustration only.
> - $(), command substitution, i.e. FOO=$(printf "\n\n\n\n\n"); seems
> unsuitable as it modifies the output by performing some whitespace
> handling, such as stripping newlines. In this example, FOO returns
> zero-length.
> - "$()", quoted, prevents the field splitting and pathname expansions,
> but doesn't protect the trailing whitespace.
> - Binary read, i.e. printf "\n\n\n\n\n" | read -N$length FOO; works
> provided the $length of the read doesn't encounter the EOF, in this
> case values 1-5. If $length>5, in this example, FOO becomes
> zero-length. For an input of unknown length, this feels impractical.
> - One possible workaround is adding a suffix and then chopping it,
> i.e. FOO="$(printf "\n\n\n\n\nmysuffix")"; FOO="${FOO%mysuffix}"
>
>
The "possible workaround" is the normal approach, in my experience the
"mysuffix" is often just a single period or lower case x.

FOO=$(printf "\n\n\n" ; printf x ;) ; FOO=${FOO%x}

You can use 'echo x' rather than 'printf x' as the trailing newline that
echo produces will be removed by the command substitution.





_______________________________________________
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to