From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 2087 invoked from network); 24 Jul 2021 07:48:49 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 24 Jul 2021 07:48:49 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1627112929; b=wyvL6aprq5SpodhMh0hWEdGm5xpFlbT2euZkmY7p6BBTIIgkvRd3OAvca4eG+6Ww1w43BPsEtI VTEPQboVoV/Lq8QvAYd5zFZvP7O72LW/g8Z0JFj2CaXiMUKkLRIk7y9lTHSPqmBVjci5AZralM Qh6t0H9h6Omas2xUK2RNqdudUyY11Rl6JRjuh8zqv838uhag8PC5bIxkTxiAUNYs+IUjSwCsu8 P7TOwKbjTiOtFUqjUZ/I0qHGAvh0FnjvjT87MVK4gRxJxUPDO/2qRtvV4hF2UY/qH9w7LudPS+ nelbZd+twY/xSRoy2bG8UNwFyOnAeAf44QncLwMu+6U73A==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-wr1-f41.google.com) smtp.remote-ip=209.85.221.41; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1627112929; bh=yslq7hmmUpU24s4ZL7hhh3ZWARGlgToCY2belXrK13E=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:MIME-Version: DKIM-Signature:DKIM-Signature; b=I3L80LjihdkTeymS7sFc/fj1nfbOj9l+mYJyIKsVSr8s93TLLrbq/jAf3kelsznrL95t2vj7Pr kxSOGa04dmaIaKolSiw5OoPkHv4pcVPjDoHIq2fjIDKIaMD8e+eCi6x5EY9/26Q4awloJaDwer 7NK0+xz7JTn2G2Xv6i+4HOMyp96tRZf462WScpMLgpPXB7pMkMh4ye7uD3wWAylEM5uAznp2RF vWt0Cal10ptSgikaPgADZETccXvd5N8BrZEdU0Ehhjd7VjeT8H0OBYtrYjcU8RXbUUnsYE8DCV cJh1kB2HCXk2jdohSns8AjcRTUglmNyzfOKfszS6JHjxdQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:To:Subject:Message-ID: Date:From:MIME-Version:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=L3CsXU2gBTXh3jsS1V1PawfrF/SpZOoMsyhMakotvyE=; b=iPWYzWIhAPMY4BgK1idOBoSth4 FYmEa9qdbT9kZEa3zAnab90rRk86B8mQrfJum9cFlwyUwAGVxzjU2N7pf3KKnxDKfHAszZ54ZPBIU HzhoSSM8qOMJN26nynTs4d1LZwXQbryyOyY+Z7mBWWFSn37PmxQIYdtwWzP/PyK/Kodd3Ea7qG01r fT+poJTwn1slTu707MhD2/X+v0OZzeWRwzlFTyZT9II0dZ/3UNrdEC4WPMeLFPFlr2uj3N7V6NHTZ 3lgeAeNGIhD04Z9iABUMBF6Oi67Wyecwah52qI4JIucT3sLjbKqF8jISPru3dv0MYf2rqlgZ3yo4m bSv72aqw==; Received: from authenticated user by zero.zsh.org with local id 1m7COv-000Ae0-3g; Sat, 24 Jul 2021 07:48:49 +0000 Authentication-Results: zsh.org; iprev=pass (mail-wr1-f41.google.com) smtp.remote-ip=209.85.221.41; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-wr1-f41.google.com ([209.85.221.41]:44932) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1m7CO3-0009u8-Op; Sat, 24 Jul 2021 07:47:57 +0000 Received: by mail-wr1-f41.google.com with SMTP id z7so4657329wrn.11 for ; Sat, 24 Jul 2021 00:47:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=L3CsXU2gBTXh3jsS1V1PawfrF/SpZOoMsyhMakotvyE=; b=QZq5E77S76wKyMUXoh6SkJ1QtsaELoWghZMi3ZGlRuz0hIRDm6UvQRNoV5THSgFIjs 8+F0Xj+c2b7Jrlh13QFrqyUolcwSMntAiq6ke9NHCTBu642exPk34LKhEKAstmjGtdzP 01PEjIJxhhaIvKEHW771rObOTMMX761j8P5JorPYQBmZrhpp6RcXTcbpsFwOzJ+KqH0J shTWTUV0X6MkhZFYL644DqnQ89lid6+xfD63S83HuSVII1UMgYbhBH7mZVNO8u0uH1Nm GhM+jqoLp8pduXM68xiKA4pBaNDHUidX2MEoqAF0Av0/OhWTgXWCbmsA+UHR35fPu44O GcLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=L3CsXU2gBTXh3jsS1V1PawfrF/SpZOoMsyhMakotvyE=; b=LALApOlbjJouSBBQE4GCWx7PGRBYKYMGI5FthjWJt82/clYKsBcTXa81BwcOd48yHU xAF7eJAkEB0k/tH462Z95eWk62WcivQHY9j2GFnUpOwtIedmb0PT5EjvP+3VefwZeYCg GiZZDZeK0onguSpbmb0Mbvibhw207Z/sHu2ZWRNL1SssBqvZsQf5A2glzXHgJsVdp+ur UDsRqe6yDIgzdQjZ1jEUT1taEbs9Wno9olYyhBqd4Tllv7hIGEQO+FPE98GIxVmUjLLU fYvkQiYcP+p0l4KqsMipqzhmYS5KYqeKVz77mr/5WyLVzm4wx/tixC2ZhisKgLs8BBx2 3yDw== X-Gm-Message-State: AOAM533agMvJN1+q8mCyvDHSsC04oStTCiz9202/PdzlFO+MSe4FaTt+ /2YlWpQ/X7VyEBtfRi4HWPw9KyR4z8Ojkurwp3L6sPeI89k= X-Google-Smtp-Source: ABdhPJyqABRlVeI8JUAUTo8ok6FNLdZfHNllEqPgXSHrk1Na87xwgYp7pZtz9hDPpGgviSxnuKw38C0Xj3yOPJiQJMo= X-Received: by 2002:adf:f405:: with SMTP id g5mr8750065wro.277.1627112874924; Sat, 24 Jul 2021 00:47:54 -0700 (PDT) MIME-Version: 1.0 From: Zach Riggle Date: Sat, 24 Jul 2021 02:47:44 -0500 Message-ID: Subject: Use of left- and right-padding with a variable padding char To: zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" X-Seq: 26803 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: As always, thank you all so much for your time. It's genuinely appreciated. I want to define a function "center", which takes $1="Some String" and $2="-" or some other default padding value. The Zsh manual on expansion says that I can do something like this, which works well and as intended: function center() { local text="${1:-hellworld}" local -i columns=${COLUMNS:-$(tput cols)} columns=$(( columns/2 )) echo ${(l:${columns}::=:::r:${columns}::=:::)text} } This works very well, and correctly centers "${text}" across the width of the terminal, with "=" padding on both sides. Perfect. However, I also want to make the padding character ("=" in the above example) be variable. The following does NOT work as intended, and I'm not sure why. My understanding is that variable expansion is inside-out, so it SHOULD work. function center() { local text="${1:-hellworld}" local pad="${2:-=}" local -i columns=${COLUMNS:-$(tput cols)} columns=$(( columns/2 )) echo ${(l:${columns}::${pad}:::r:${columns}::${pad}:::)text} } center "hello" "_" The value in $1 is correctly centered, but it is padded with the LITERAL value '${pad}', rather than the expansion of ${pad}. I expect there's some documentation that I haven't read yet, any tips would be useful. Zach Riggle