• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

国民时代

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

Linux命令:readonly

readonly [-aAf] [name[=value] ...] or readonly -p

 -A  表示后面的name变量都是关联数组

-a  表示后面的name变量都是index数组

-f  表示后面的name都是函数

不带任何name,或者-p,打印所有只读name,包括变量、函数。

-aA 同时出现,-A优先。

 如果-aAf 和名字不一致,会返回非0。

name后带value和不带value的区别是,带value表示在定义时就声明只读;不带value表示先定义后,后声明。对变量声明,既可以在定义变量时声明,也可以在变量定义后再声明。

对于函数,只能先定义后声明。

 取消只读????

help readonly

 1 readonly: readonly [-aAf] [name[=value] ...] or readonly -p
 2     Mark shell variables as unchangeable.
 3 
 4     Mark each NAME as read-only; the values of these NAMEs may not be
 5     changed by subsequent assignment.  If VALUE is supplied, assign VALUE
 6     before marking as read-only.
 7 
 8     Options:
 9       -a        refer to indexed array variables
10       -A        refer to associative array variables
11       -f        refer to shell functions
12       -p        display a list of all readonly variables and functions
13 
14     An argument of `--' disables further option processing.
15 
16     Exit Status:
17     Returns success unless an invalid option is given or NAME is invalid.

 例子

#  声明只读变量。
readonly var=value

# 声明只读数组
readonly -a array=(val1 val2 val3)
#  声明只读函数
readonly -f f1

 

 

 

本篇文章出自“国民时代”,转载请注明转载出处。

posted on 2019-03-30 14:02  国民时代  阅读(3059)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3