0

bash スクリプトでファイルをコピーしたいのですが、時間の経過とともにファイル名が変わります。ただし、ファイル名の最初と最後は同じままです。

方法があるので、次のようにファイルを取得します:

  cp start~end.jar

どこで ~ は何でもいいですか?

これが違いを生む場合、cpコマンドはubuntuマシンでbashスクリプトを実行します。

4

2 に答える 2

4

glob(start*end)は、一致するすべてのファイルを提供します。

Expansion > Pathname Expansion > Pattern Matchingより具体的な制御については、bashマニュアルのセクションを確認してください

   *      Matches any string, including the null string.
   ?      Matches any single character.
   [...]  Matches any one of the enclosed characters.  A pair of characters separated by a hyphen denotes a range expression; any character that sorts between those two characters, inclusive, using the current locale's collat-
          ing sequence and character set, is matched.  If the first character following the [ is a !  or a ^ then any character not enclosed is matched.  The sorting order of characters in range expressions  is  determined  by
          the  current locale and the value of the LC_COLLATE shell variable, if set.  A - may be matched by including it as the first or last character in the set.  A ] may be matched by including it as the first character in
          the set.

有効にするとextglob

  ?(pattern-list)
         Matches zero or one occurrence of the given patterns
  *(pattern-list)
         Matches zero or more occurrences of the given patterns
  +(pattern-list)
         Matches one or more occurrences of the given patterns
  @(pattern-list)
         Matches one of the given patterns
  !(pattern-list)
         Matches anything except one of the given patterns
于 2013-03-06T16:16:42.310 に答える
2

a を使用しglobて変数テキストをキャプチャします。

cp start*end.jar
于 2013-03-06T16:11:55.597 に答える