[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] Does declare in function define local variables?
From: |
Peng Yu |
Subject: |
[Help-bash] Does declare in function define local variables? |
Date: |
Fri, 7 Dec 2018 17:42:39 -0600 |
Hi,
The manual says
"""
The -g option forces variables to be created or modified at the global
scope, even when declare is executed in a shell function.
"""
`x` is not accessible outside the function. Is a variable declared
(without -g) in function local?
$ cat ./main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
function f {
declare x
x=10
declare -p x
}
x=42
f
declare -p x
$ ./main.shdeclare -- x="10"
declare -- x="42"
--
Regards,
Peng
- [Help-bash] Does declare in function define local variables?,
Peng Yu <=