Shell/Bash
- [bash] print되는 string에 컬러 넣기 2022.02.24
- [bash] declare 란? 2022.02.24
[bash] print되는 string에 컬러 넣기
2022. 2. 24. 09:29
[bash] declare 란?
2022. 2. 24. 08:57
728x90
반응형
declare: declare [-afFirtx] [-p] [name[=value] ...]
Declare variables and/or give them attributes. If no NAMEs are given, then display the values of variables instead. The -p option will display the attributes and values of each NAME.
The flags are:
-a to make NAMEs arrays (if supported)
-f to select from among function names only
-F to display function names (and line number and source file name if debugging) without definitions.
-i to make NAMEs have the `integer' attribute.
-r to make NAMEs readonly
-t to make NAMEs have the `trace' attribute
-x to make NAMEs export.
Variables with the integer attribute have arithmetic evaluation (see `let') done when the variable is assigned to.
When displaying values of variables, -f displays a function's name and definition. The -F option restricts the display. to function name only.
Using `+' instead of `-' turns off the given attribute instead. When used in a function, makes NAMEs local, as with the `local' command.
bash script의 Variable의 경우 보통 type 없이 생성하고 사용한다. 하지만 declare로 선언할 경우 type과 접근권한을 설정해줄 수 있다.
-a : Array
$ declare -a os_name=(Ubuntu Mint Kubuntu lubuntu Debian)
$ echo ${os_name[@]}
$ declare -A os_family
$ os_family["Redhat"]="Fedora"
$ os_family["Arch"]="Manjaro"
$ os_family["Debian"]="Ubuntu"
$ echo ${os_family[@]}
-f : Select Function name
$ function hello_world(){ echo "Linux Geeks"; }
$ declare -f hello_world SIGINT(2) ↵ 108 15:53:10
hello_world () {
echo "Linux Geeks"
}
-i : Integer attribute
$ declare -i num=10
$ echo $num
10
-x : Export attribute
$ declare -x name=declareTest
$ sh -c “echo $name”
declareTest
-r : Readonly attribute
$ declare -r num=10
$ num=11
-bash: no: readonly variable
728x90
반응형
'Shell > Bash' 카테고리의 다른 글
[bash] print되는 string에 컬러 넣기 (0) | 2022.02.24 |
---|