teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

動作環境を実行結果を追加

2020/11/27 01:57

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,6 @@
1
1
  指定のディレクトリ(サブディレクトリ含む)から条件に一致するファイル名を出して処理をしていくスクリプトを作りたい。
2
- findとforを組み合わせて作りましたが、空白スペースが入っているようなファイルが存在するとうまく処理ができない問題があります。
2
+ findとforを組み合わせて作りましたが、空白スペースが入っているようなファイル(例:aaa aaa.txt)が存在するとうまく処理ができない問題があります。
3
+
3
4
  ```
4
5
  for file in `find ディレクトリ名 -type f -name '*.txt' 2>/dev/null`; do
5
6
  ```
@@ -10,4 +11,52 @@
10
11
  syntax error near unexpected token `<'
11
12
  ```
12
13
 
13
- コピペミスではないと思いますが、使え無さそうなので他に実現する方法はありませんでしょうか?
14
+ コピペミスではないと思いますが、使え無さそうなので他に実現する方法はありませんでしょうか?
15
+
16
+ ---
17
+
18
+ 追記:参考にしたページのものは動作するという回答を頂いておりますが、やはりこちらの環境では動作しないように思えます。
19
+ DockerのCentOSを使っておりそれが問題なのかどうかがわかりませんが、テスト用に作成したスクリプトと環境を記述しておきます。
20
+
21
+ 環境
22
+
23
+ ```
24
+ [root@bbec28a1ab2f ~]# uname -a
25
+ Linux bbec28a1ab2f 5.4.39-linuxkit #1 SMP Fri May 8 23:03:06 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
26
+
27
+ [root@bbec28a1ab2f ~]# bash --version
28
+ GNU bash, version 4.4.19(1)-release (x86_64-redhat-linux-gnu)
29
+ Copyright (C) 2016 Free Software Foundation, Inc.
30
+ License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
31
+
32
+ This is free software; you are free to change and redistribute it.
33
+ There is NO WARRANTY, to the extent permitted by law.
34
+
35
+ [root@bbec28a1ab2f ~]# find --version
36
+ find (GNU findutils) 4.6.0
37
+ Copyright (C) 2015 Free Software Foundation, Inc.
38
+ License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
39
+ This is free software: you are free to change and redistribute it.
40
+ There is NO WARRANTY, to the extent permitted by law.
41
+
42
+ Written by Eric B. Decker, James Youngman, and Kevin Dalley.
43
+ Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD) CBO(level=2)
44
+ ```
45
+
46
+ 動作テスト用スクリプト
47
+
48
+ ```
49
+ #!/bin/bash
50
+
51
+ while read f; do
52
+ echo "${file}"
53
+ done < <(find . -type f)
54
+ ```
55
+
56
+ 実行結果
57
+
58
+ ```
59
+ # sh test.sh
60
+ test.sh: line 5: syntax error near unexpected token `<'
61
+ test.sh: line 5: `done < <(find . -type f)'
62
+ ```