Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Dumb (?) Q: how to do brace expansion in /bin/sh?

    Scheduled Pinned Locked Moved General pfSense Questions
    7 Posts 5 Posters 670 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • MrPeteM
      MrPete
      last edited by

      The pfSense default shell allows this simple filename/etc expansion:
      ls {a,b,c,d}.txt

      But the default /bin/sh shell says "no such file or directory" with that.

      How is that done in /bin/sh?

      Why I ask: things like ACME action lists allow a shell command. It would sure be helpful to have expansion capability there!

      NollipfSenseN 1 Reply Last reply Reply Quote 0
      • NollipfSenseN
        NollipfSense @MrPete
        last edited by

        @mrpete I tried looking there as well as try your command...it doesn't seems to contain nothing but machine language...hope someone more senior can help.

        Screenshot 2023-03-22 at 1.18.29 PM.png

        pfSense+ 23.09 Lenovo Thinkcentre M93P SFF Quadcore i7 dual Raid-ZFS 128GB-SSD 32GB-RAM PCI-Intel i350-t4 NIC, -Intel QAT 8950.
        pfSense+ 23.09 VM-Proxmox, Dell Precision Xeon-W2155 Nvme 500GB-ZFS 128GB-RAM PCIe-Intel i350-t4, Intel QAT-8950, P-cloud.

        1 Reply Last reply Reply Quote 0
        • F
          FSC830
          last edited by FSC830

          The a, b, c ,d are only placeholders, you need to type something useful for that. 😊
          The command allows to limit the outcome. See i.e. an unlimited listing and a listing showing only files starting with h or i and an extension .php:

          user@vmmt82:/var/www/wetter/meteo$ ls -al
          total 388
          drwxr-xr-x 18 www-data www-data  4096 Mär 22 11:08 .
          drwxr-xr-x  3 www-data www-data  4096 Mär 17 16:48 ..
          drwxr-xr-x  8 www-data www-data  4096 Mär 18 01:20 admin
          -rw-r--r--  1 www-data www-data 73438 Mär 16 19:12 api.php
          drwxr-xr-x  2 www-data www-data  4096 Mär 16 19:12 backup
          drwxr-xr-x  2 www-data www-data  4096 Mär 22 19:57 cache
          -rwxrwxrwx  1 www-data www-data  6499 Mär 17 18:46 config.php
          drwxr-xr-x  5 www-data www-data  4096 Mär 16 19:12 css
          drwxr-xr-x  2 www-data www-data  4096 Mär 16 19:12 custom
          -rw-r--r--  1 www-data www-data 28797 Mär 16 19:12 footer.php
          -rw-r--r--  1 www-data www-data    31 Mär 17 16:20 fs_info.php
          -rw-r--r--  1 www-data www-data 32298 Mär 16 19:12 header.php
          drwxr-xr-x  4 www-data www-data  4096 Mär 16 19:12 homepage
          drwxr-xr-x 10 www-data www-data  4096 Mär 16 19:12 icons
          drwxr-xr-x 12 www-data www-data  4096 Mär 16 19:12 imgs
          -rw-r--r--  1 www-data www-data 34619 Mär 16 19:12 indexDesktop.php
          -rw-r--r--  1 www-data www-data  3658 Mär 16 19:12 indexFull.php
          -rw-r--r--  1 www-data www-data 27427 Mär 16 19:12 indexMobile.php
          -rw-r--r--  1 www-data www-data  7204 Mär 16 19:12 index.php
          drwxr-xr-x  3 www-data www-data  4096 Mär 16 19:12 install
          drwxr-xr-x  2 www-data www-data  4096 Mär 20 10:37 lang
          drwxr-xr-x  4 www-data www-data  4096 Mär 16 19:12 load
          -rw-r--r--  1 www-data www-data 51620 Mär 20 16:06 menu.php
          -rw-r--r--  1 www-data www-data   524 Mär 22 20:00 meteotemplateLive.txt
          drwxr-xr-x  3 www-data www-data  4096 Mär 16 19:12 mobile
          drwxr-xr-x 11 www-data www-data  4096 Mär 16 19:12 pages
          -rw-r--r--  1 www-data www-data    65 Mär 22 11:08 php_version.php
          -rw-r--r--  1 www-data www-data    59 Mär 22 11:04 php_vers.php
          drwxr-xr-x 13 www-data www-data  4096 Mär 18 18:07 plugins
          drwxr-xr-x  6 www-data www-data  4096 Mär 17 10:53 scripts
          -rw-r--r--  1 www-data www-data  2471 Mär 16 19:12 sitemap.php
          -rw-r--r--  1 www-data www-data  8733 Mär 22 19:17 sitemap.txt
          -rw-r--r--  1 www-data www-data  1452 Mär 16 19:12 sitemapXML.php
          drwxr-xr-x  2 www-data www-data  4096 Mär 16 19:12 update
          -rw-r--r--  1 www-data www-data  1779 Mär 16 19:12 userSettings.php
          -rw-r--r--  1 www-data www-data    59 Mär 22 11:04 version.php
          
          user@vmmt82:/var/www/wetter/meteo$ ls -al {h*,i*}.php
          -rw-r--r-- 1 www-data www-data 32298 Mär 16 19:12 header.php
          -rw-r--r-- 1 www-data www-data 34619 Mär 16 19:12 indexDesktop.php
          -rw-r--r-- 1 www-data www-data  3658 Mär 16 19:12 indexFull.php
          -rw-r--r-- 1 www-data www-data 27427 Mär 16 19:12 indexMobile.php
          -rw-r--r-- 1 www-data www-data  7204 Mär 16 19:12 index.php
          
          

          Regards

          Edit: Works in shell without issues...

          [23.01-RELEASE][admin@firewall.home]/root: ls -al {check_mount,qrmount}.sh
          -rwxr-xr-x  1 root  wheel  321 Dec 12 10:37 check_mount.sh
          -rwxr-xr-x  1 root  wheel   66 Dec 12 10:38 qrmount.sh
          [23.01-RELEASE][admin@firewall.home]/root:
          

          Edit: Got it. You mean the curly braces command does not work in pfSense GUI - Diagnostics when running a shell command.
          Seems, that the GUI cant interprete/escape the curly braces.

          Just looked in PHP file: the function "htmlspecialchars" is used for translating special characters, but referring to PHP manual this function does not know the curly braces. So only solutions seems to be running such a command at command lie (by SSH or serial).

          1 Reply Last reply Reply Quote 0
          • stephenw10S
            stephenw10 Netgate Administrator
            last edited by

            The default shell is csh not sh. That's probably what you're seeing.

            MrPeteM 1 Reply Last reply Reply Quote 1
            • MrPeteM
              MrPete @stephenw10
              last edited by

              @stephenw10 Exactly.
              Works fine in the normal interactive shell.

              It's other situations that use sh... such as the "acme scripts" field...

              1 Reply Last reply Reply Quote 0
              • jimpJ
                jimp Rebel Alliance Developer Netgate
                last edited by

                I don't think /bin/sh supports that kind of glob/brace expansion.

                   Pathname Expansion (File Name Generation)
                     Unless the -f option is set, file name generation is performed after word
                     splitting is complete.  Each word is viewed as a series of patterns,
                     separated by slashes.  The process of expansion replaces the word with
                     the names of all existing files whose names can be formed by replacing
                     each pattern with a string that matches the specified pattern.  There are
                     two restrictions on this: first, a pattern cannot match a string
                     containing a slash, and second, a pattern cannot match a string starting
                     with a period unless the first character of the pattern is a period.  The
                     next section describes the patterns used for Pathname Expansion, the four
                     varieties of parameter expansion for substring processing and the case
                     command.
                
                   Shell Patterns
                     A pattern consists of normal characters, which match themselves, and
                     meta-characters.  The meta-characters are ‘*’, ‘?’, and ‘[’.  These
                     characters lose their special meanings if they are quoted.  When command
                     or variable substitution is performed and the dollar sign or back quotes
                     are not double-quoted, the value of the variable or the output of the
                     command is scanned for these characters and they are turned into meta-
                     characters.
                
                     An asterisk (‘*’) matches any string of characters.  A question mark
                     (‘?’) matches any single character.  A left bracket (‘[’) introduces a
                     character class.  The end of the character class is indicated by a ‘]’;
                     if the ‘]’ is missing then the ‘[’ matches a ‘[’ rather than introducing
                     a character class.  A character class matches any of the characters
                     between the square brackets.  A locale-dependent range of characters may
                     be specified using a minus sign.  A named class of characters (see
                     wctype(3)) may be specified by surrounding the name with ‘[:’ and ‘:]’.
                     For example, ‘[[:alpha:]]’ is a shell pattern that matches a single
                     letter.  The character class may be complemented by making an exclamation
                     point (‘!’) the first character of the character class.  A caret (‘^’)
                     has the same effect but is non-standard.
                
                     To include a ‘]’ in a character class, make it the first character listed
                     (after the ‘!’ or ‘^’, if any).  To include a ‘-’, make it the first or
                     last character listed.
                

                No mention of {} style in there.

                Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

                Need help fast? Netgate Global Support!

                Do not Chat/PM for help!

                MrPeteM 1 Reply Last reply Reply Quote 2
                • MrPeteM
                  MrPete @jimp
                  last edited by

                  @jimp I was afraid of that. :(

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.