- 论坛徽章:
- 0
|
- ll
- total 32
- -rw-r--r-- 1 root root 0 Jul 13 12:22 a bak
- -rw-r--r-- 1 root root 0 Jul 13 12:22 b bak
- -rw-r--r-- 1 root root 0 Jul 13 12:22 c bak
- -rwxr-xr-x 1 root root 137 Jul 12 17:29 test01.sh
- -rwxr-xr-x 1 root root 344 Jul 13 12:16 test02.sh
- -rwxr-xr-x 1 root root 347 Jul 13 14:49 test03.sh
- -rwxr-xr-x 1 root root 294 Jul 13 15:39 test04.sh
- -rwxr-xr-x 1 root root 87 Jul 13 15:25 test05.sh
- -rwxr-xr-x 1 root root 221 Jul 14 08:45 test06.sh
- -rwxr-xr-x 1 root root 91 Jul 13 16:58 test07.sh
- -rwxr-xr-x 1 root root 190 Jul 13 17:29 test08.sh
复制代码 想匹配有bak的文件
测试一,- #!/bin/sh
- SAVEIFS=$IFS;
- #IFS=$'\n'
- IFS='\n'
- for file in `ls -1 /tmp/shell/bash`
- do
- if [[ "$file" =~ "bak" ]]; then
- echo $file
- fi
- # echo "$file"
- done
- IFS=$SAVEIFS
复制代码 执行结果:
a bak
b bak
c bak
test01.sh
test02.sh
test03.sh
test04.sh
test05.sh
test06.sh
test07.sh
test08.sh
测试二,- #!/bin/sh
- SAVEIFS=$IFS;
- IFS=$'\n'
- for file in `ls -1 /tmp/shell/bash`
- do
- if [[ "$file" =~ "bak" ]]; then
- echo $file
- fi
- # echo "$file"
- done
- IFS=$SAVEIFS
复制代码 执行结果:
a bak
b bak
c bak
我在 本论坛 的帖子 <某目录下含有空格的文件,如何处理> 有这个问题, 是黑哥提出用IFS=$'\n'的,想问为什么,黑兄要我man bash 嘿嘿(man了半天,没看出所以然来,所以再开一帖) |
|