Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're not too far off. My first fix is changing line 3 to the following:</p> <pre><code>ls -- "${others}".* </code></pre> <p>This will expand <code>$others</code> and allow the globbing to happen. It's the shells responsibility to expand the <code>*</code> to the list of all matching filenames. The list of filenames is then sent to <code>ls</code>. It sounds like in most cases ls will see something like this:</p> <pre><code>file1.001 file1.002 file1.003 ... </code></pre> <p>But, when no files are present, the shell passes the glob to ls and it will see asterisk:</p> <pre><code>file1.* </code></pre> <p>Thus, your line, <code>ls $others"*"</code> appends a literal asterisk which ls will see.</p> <p>Unless you have a file name <code>file1.*</code> (with a literal asterisks), <code>ls</code> will fail.</p> <p>Another option is to use basename:</p> <pre><code>first="$1" others=`basename -- "$first" .001` ls -- "${others}".* </code></pre> <p>Using <code>basename</code> gives you the advantage that it can remove directories, etc.</p> <p>However, as others have pointed out, depending on what you're doing with the list of files, <code>find</code> may be better.</p> <p>EDIT: The double-hyphen doesn't work on all *nix variants but tells the <code>ls</code> and <code>basename</code> commands that no other cli arguments follow. Quoting your variables may be a best practices but I prefer the simplicity of leaving them off unless the data isn't trusted. Know your data and quote appropriately.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload