* (no subject)
@ 2023-10-12 18:39 henman
2023-10-12 18:51 ` How to compare for control codes in a string Bart Schaefer
2023-10-12 22:22 ` Pier Paolo Grassi
0 siblings, 2 replies; 3+ messages in thread
From: henman @ 2023-10-12 18:39 UTC (permalink / raw)
To: zsh-users
Subject: How to compare for control codes in a string
X-Mailer: MH-E 8.6+git; GNU Mailutils 3.16; Emacs 29.1
--------
I want to see if the 1st character in a string is a formfeed and then remove it.
I use the following script to check it
if [[ $line[1] == '\f' ]] # Check if the 1st character is a formfeed
then tmpline=${line[@]:1} # strip the ^f off
fi
but it's not working. How should it be checked?
Thank you.
---------
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to compare for control codes in a string
2023-10-12 18:39 henman
@ 2023-10-12 18:51 ` Bart Schaefer
2023-10-12 22:22 ` Pier Paolo Grassi
1 sibling, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2023-10-12 18:51 UTC (permalink / raw)
To: henman; +Cc: Zsh Users
On Thu, Oct 12, 2023 at 11:39 AM henman <dhenman@gmail.com> wrote:
>
> if [[ $line[1] == '\f' ]] # Check if the 1st character is a formfeed
That's checking for the two literal characters backslash and f which
will never match a single character as in $line[1]. You probably
meant
if [[ $line[1] == $'\f' ]] # Check if the 1st character is a formfeed
Except with $'...', processing of \f \t \n etc. is not done as part of
string interpolation, though you might be fooled into thinking so
because it may instead be done by the print and echo commands.
> then tmpline=${line[@]:1} # strip the ^f off
The [@] there doesn't mean anything when $line is not an array, though
it's harmless.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re:
2023-10-12 18:39 henman
2023-10-12 18:51 ` How to compare for control codes in a string Bart Schaefer
@ 2023-10-12 22:22 ` Pier Paolo Grassi
1 sibling, 0 replies; 3+ messages in thread
From: Pier Paolo Grassi @ 2023-10-12 22:22 UTC (permalink / raw)
To: henman; +Cc: zsh-users
[-- Attachment #1: Type: text/plain, Size: 546 bytes --]
Il giorno gio 12 ott 2023 alle 20:40 henman <dhenman@gmail.com> ha scritto:
> Subject: How to compare for control codes in a string
> X-Mailer: MH-E 8.6+git; GNU Mailutils 3.16; Emacs 29.1
> --------
>
>
> I want to see if the 1st character in a string is a formfeed and then
> remove it.
>
> I use the following script to check it
>
> if [[ $line[1] == '\f' ]] # Check if the 1st character is a formfeed
> then tmpline=${line[@]:1} # strip the ^f off
> fi
>
hello, this should work:
if [[ $line[1] == $'\f' ]]
cheers
[-- Attachment #2: Type: text/html, Size: 1703 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-10-12 22:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-12 18:39 henman
2023-10-12 18:51 ` How to compare for control codes in a string Bart Schaefer
2023-10-12 22:22 ` Pier Paolo Grassi
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).