I'm working on a project where I have to process the contents of a directory passed in as an argument, and I need to include invisible files (ones that start with .) as well. This is how I'm approaching it
#!/bin/bash
cd $1
for file in `dir -a -d * `;
do
#more code blah blah
Run Code Online (Sandbox Code Playgroud)
even though I use the -a tag on the dir command, it still ignores invisible files. Any ideas why?
Just do:
#!/bin/bash
shopt -s dotglob
cd "$1"
for file in *; do
# more code blah blah
done
Run Code Online (Sandbox Code Playgroud)
From the bash manpage
When a pattern is used for filename expansion, the character ‘.’ at the start of a filename or immediately following a slash must be matched explicitly, unless the shell option dotglob is set.
| 归档时间: |
|
| 查看次数: |
720 次 |
| 最近记录: |