我想编写一个 Posix shell 脚本函数,该函数将匹配需要扩展的空格和通配符 (*?) 的模式。在 Python 中,glob.glob('/tmp/hello world*')将返回正确的列表。我如何在 shell 中执行此操作?
#!/bin/sh
## this function will list
## all of the files in the /tmp
## directory that match pattern
f() {
PATTERN="$1"
ls -1 "/tmp/$PATTERN"
}
touch '/tmp/hello world {1,2,3}.txt'
f 'hello world*'
Run Code Online (Sandbox Code Playgroud) 这是C和C++的样式问题.你比较喜欢哪个
void f() {
const char * x = g();
if (x == NULL) {
//process error
}
// continue function
}
Run Code Online (Sandbox Code Playgroud)
或这个:
void f() {
const char * x = g();
if (! x) {
//process error
}
// continue function
}
Run Code Online (Sandbox Code Playgroud)
?前者更清晰,但后者则不那么冗长.