[prev in list] [next in list] [prev in thread] [next in thread]
List: ast-users
Subject: Re: [ast-users] Raw command substitution "$()"
From: Icarus Sparry <i.sparry+astuser () gmail ! com>
Date: 2013-12-16 21:42:11
Message-ID: 52AF73B3.70301 () gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
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.
[Attachment #5 (text/html)]
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 12/16/2013 1:02 PM, Eugene Schulman
(BLOOMBERG/ 120 PARK) wrote:<br>
</div>
<blockquote cite="mid:52AF6A4901F6079C00390AE9_0_89941@p057"
type="cite">
<title></title>
<!-- rte-version 0.2 9947551637294008b77bce25eb683dac -->
<div class="rte-style-maintainer" style="font-family: Arial,
'BB.Proportional'; white-space: pre-wrap; font-size: small;"
data-color="global-default" data-bb-font-size="medium">Hi guys,
<div>I'm looking for a method to do raw command substitution.</div>
<div><br>
</div>
<div>
<div>The issue:</div>
<div>- 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.</div>
<div><br>
</div>
<div>Examples. printf is used below for illustration only.</div>
<div>- $(), 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.</div>
</div>
<div>- "$()", quoted, prevents the field splitting and pathname
expansions, but doesn't protect the trailing whitespace.</div>
<div>- 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.</div>
<div>- One possible workaround is adding a suffix and then
chopping it, i.e. FOO="$(printf "\n\n\n\n\nmysuffix")";
FOO="${FOO%mysuffix}"</div>
<div><br>
</div>
<br>
</div>
</blockquote>
The "possible workaround" is the normal approach, in my experience
the "mysuffix" is often just a single period or lower case x.<br>
<br>
FOO=$(printf "\n\n\n" ; printf x ;) ; FOO=${FOO%x}<br>
<br>
You can use 'echo x' rather than 'printf x' as the trailing newline
that echo produces will be removed by the command substitution.<br>
<br>
<br>
<br>
<br>
<br>
</body>
</html>
_______________________________________________
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic