help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding option to select file types


From: Lawrence Velázquez
Subject: Re: Adding option to select file types
Date: Mon, 05 Jul 2021 20:44:57 -0400
User-agent: Cyrus-JMAP/3.5.0-alpha0-530-gd0c265785f-fm-20210616.002-gd0c26578

On Mon, Jul 5, 2021, at 7:47 PM, lisa-asket@perso.be wrote:
> Why does printf complain with the following help displays?

It would be helpful to see these complaint(s).

>         frmt="%s"
>         printf $frmt "Print text surrounding line numbers from named files.\n"
>         printf $frmt "-d DIR\n--directory=DIR\n"
>         printf $frmt "    Directory.\n"
>         printf $frmt "-e TYPE\n--extension=TYPE\n"
>         printf $frmt "    Extension defining file type.  Multiple file are\n"
>         printf $frmt "    separated by a comma (e.g. `-e org,texi`).\n"

I am going to guess that the error is coming from this command.
Command substitution -- including the legacy `...` form -- is
performed inside double quotes.

    bash-5.1$ printf '%s\n' "foo `date` bar"
    foo Mon Jul  5 20:27:46 EDT 2021 bar

Your shell tries to execute the command '-e org,texi', but you
presumably do not have a utility called '-e', so the execution
fails.  This unwanted command substitution would not happen if
you used single quotes instead of double quotes.

https://mywiki.wooledge.org/Quotes#Types_of_quoting

>         printf $frmt "-p NUM\n--startline=NUM.\n"
>         printf $frmt "    Start line number.\n"
>         printf $frmt "-q NUM\n--stopline=NUM.\n"
>         printf $frmt "    Stop line number.\n"

I'm not going to address the ineffectual '\n's in the arguments
because this whole approach seems needlessly involved.  You might
instead consider using a quoted here-document, which does not have
issues with expansions, substitutions, or apostrophes.

    cat <<'EOF'
Print text surrounding line numbers from named files.
-d DIR
--directory=DIR
    Directory.
-e TYPE
--extension=TYPE
    Extension defining file type.  Multiple file are
    separated by a comma (e.g. `-e org,texi`).
-p NUM
--startline=NUM.
    Start line number.
-q NUM
--stopline=NUM.
    Stop line number.
EOF

https://mywiki.wooledge.org/BashGuide/InputAndOutput#Heredocs_And_Herestrings

-- 
vq



reply via email to

[Prev in Thread] Current Thread [Next in Thread]