zsh-users
 help / color / mirror / code / Atom feed
From: Alex Satrapa <grail@goldweb.com.au>
To: zzapper <zsh@rayninfo.co.uk>
Cc: Zsh-Users List <zsh-users@zsh.org>
Subject: Re: Can I test if a parameter expansion has worked
Date: Fri, 16 Sep 2022 10:41:18 +1000	[thread overview]
Message-ID: <1EF0D745-0597-4C62-9FA0-4D6BDB8F40FC@goldweb.com.au> (raw)
In-Reply-To: <f93d2561-a8d8-c952-2aeb-8bcf43eef1cb@rayninfo.co.uk>

[-- Attachment #1: Type: text/plain, Size: 755 bytes --]

On 15 Sep 2022, at 17:34, zzapper <zsh@rayninfo.co.uk> wrote:
> 
> I suppose I should be testing the filename before passing it to the expansion
> 
> if [[ $f =~ '.jpg|gif|png|jpeg' ]] ;then echo 'ok' ;else echo 'nok' ;fi

That’s how I’d approach it.

Also make sure to check that the new file name doesn’t exist. A common workaround to trying to name a file the same as an existing file is to add a numerical suffix. Then you need to check if there’s already a file/some files with numerical suffixes and figure out what the next suffix needs to be. One example I saw was to start with N=1, then keep incrementing that counter until file_s_${N} doesn’t exist.

Anyway, if you need help overthinking stuff I’ll be around.

Alex


[-- Attachment #2: Type: text/html, Size: 2758 bytes --]

  parent reply	other threads:[~2022-09-16  0:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-14 10:03 zzapper
2022-09-14 18:36 ` Bart Schaefer
2022-09-15  0:08 ` Alex Satrapa
2022-09-15  7:34 ` zzapper
2022-09-15  8:24   ` Peter Stephenson
2022-09-15  8:38     ` zzapper
2022-09-15 16:48   ` Bart Schaefer
2022-09-20  7:14     ` david rayner
2022-09-16  0:41   ` Alex Satrapa [this message]
2022-09-20 12:49   ` Stephane Chazelas
2022-09-20 13:25   ` Stephane Chazelas
2022-09-20 13:31     ` Stephane Chazelas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1EF0D745-0597-4C62-9FA0-4D6BDB8F40FC@goldweb.com.au \
    --to=grail@goldweb.com.au \
    --cc=zsh-users@zsh.org \
    --cc=zsh@rayninfo.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).