# 如何使用 google 的 package 代码风格来编写 shell 代码。

**URL:** <https://discuss.kubernetes.io/t/google-package-shell/20426>\
**Category:** Chinese\
**Tags:** development\
**Created:** [June 25, 2022, 2:37am UTC](https://discuss.kubernetes.io/t/google-package-shell/20426 "2022-06-25T02:37:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![taojintianxia](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/taojintianxia/32/10330_2.png) [@taojintianxia](https://discuss.kubernetes.io/u/taojintianxia)\
**Post date:** [June 25, 2022, 2:37am UTC](https://discuss.kubernetes.io/t/google-package-shell/20426/1 "2022-06-25T02:37:38Z")

</div>

在 google 的 [shell style guide](https://google.github.io/styleguide/shellguide.html) 中，我们可以看到 package 这一部分。

```shell
# Single function
my_func() {
  …
}

# Part of a package
mypackage::my_func() {
  …
}

```

而且我在 k8s 的 shell 代码中看到大量的这种用法：

```shell
function kube::util::sourced_variable {
  # Call this function to tell shellcheck that a variable is supposed to
  # be used from other calling context. This helps quiet an "unused
  # variable" warning from shellcheck and also document your code.
  true
}

kube::util::sortable_date() {
  date "+%Y%m%d-%H%M%S"
}

```

> [https://github.com/kubernetes/kubernetes/blob/master/hack/lib/util.sh](https://github.com/kubernetes/kubernetes/blob/master/hack/lib/util.sh)

可是当我自己去使用这种风格编写代码的时候

```shell
utils::curl() {
  echo "curl"
}

utils::curl

```

I got an error util.sh: line 11: `utils::curl’: not a valid identifier

是不是太明白这个风格的 shell 是需要什么配置还是我哪里写错了。
