2024-03-30 15:10:12 +00:00
|
|
|
# RUN: %fish %s | %filter-ctrlseqs
|
2020-01-08 08:03:34 +00:00
|
|
|
|
|
|
|
# A for-loop-variable is a local variable in the enclosing scope.
|
|
|
|
set -g i global
|
|
|
|
# implicit set -l i $i
|
|
|
|
for i in local
|
|
|
|
end
|
|
|
|
set -ql i && echo $i
|
|
|
|
# CHECK: local
|
|
|
|
|
|
|
|
# The loop variable is initialized with any previous value.
|
|
|
|
set -g j global
|
|
|
|
for j in
|
|
|
|
end
|
|
|
|
set -ql j && echo $j
|
|
|
|
# CHECK: global
|
|
|
|
|
|
|
|
# Loop variables exist only locally in the enclosing local scope.
|
|
|
|
# They do not modify other local/global/universal variables.
|
|
|
|
set -g k global
|
|
|
|
begin
|
|
|
|
for k in local1
|
|
|
|
echo $k
|
|
|
|
# CHECK: local1
|
|
|
|
for k in local2
|
|
|
|
end
|
|
|
|
echo $k
|
|
|
|
# CHECK: local2
|
|
|
|
end
|
|
|
|
echo $k
|
|
|
|
# CHECK: local1
|
|
|
|
end
|
|
|
|
echo $k
|
|
|
|
# CHECK: global
|
2021-10-28 14:28:54 +00:00
|
|
|
|
|
|
|
function foo --on-variable foo
|
|
|
|
echo foo set
|
|
|
|
end
|
|
|
|
|
|
|
|
for foo in 1 2 3
|
|
|
|
true
|
|
|
|
end
|
|
|
|
# CHECK: foo set
|
|
|
|
# CHECK: foo set
|
|
|
|
# CHECK: foo set
|