小编Hal*_*ary的帖子

带空格的 shell glob 扩展

我想编写一个 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)

bash shell glob sh

2
推荐指数
1
解决办法
2427
查看次数

最佳实践:如何在C/C++中检查NULL返回值

这是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)

?前者更清晰,但后者则不那么冗长.

c c++ null

0
推荐指数
1
解决办法
5322
查看次数

标签 统计

bash ×1

c ×1

c++ ×1

glob ×1

null ×1

sh ×1

shell ×1