Questions tagged [declare]
The declare tag has no summary.
17 questions
7
votes
1
answer
559
views
bash - how to remove a local variable (inside a function)
I've read what's listed in Bibliography regarding unset, declare, local and "Shell Functions".
My version of Bash is
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
var='outer'
...
6
votes
1
answer
248
views
What is bash declare built-in reporting here?
Our RHEL8 servers don't have nc available, but at some time in the past someone using this shared account defined an nc function:
$ declare -f nc | head -1
nc ()
$
I am trying to determine where this ...
1
vote
1
answer
36
views
Obtaining the delta for 'declare -F' between current and clean shell environments
Main question: how would one get the delta for declare -F, between that in the current shell, and that as if the shell just started (first two commands below). $(declare -F) does not solve the ...
5
votes
2
answers
522
views
Is the output of `declare -p <variable>` in bash guaranteed to be reusable as shell input?
This is specifically about bash's declare - the general case is pretty exhaustively dealt with in this answer (which mentions "the typeset/declare/export -p output of ksh93, mksh, zsh" but ...
0
votes
1
answer
87
views
Bash create parameter named array within function
I'm attempting to write a function that writes arrays with a name that's passed in. Given the following bash function:
function writeToArray {
local name="$1"
echo "$name"
...
1
vote
2
answers
989
views
Cannot Display Bash Functions within FZF Preview Window
How do I get the FZF Preview Window to Display Functions from my Current Bash Environment?
I want to list my custom bash functions using FZF, and view the code of a selected function in the FZF ...
3
votes
1
answer
402
views
Why does substituting eval with declare (for creating dynamic variables) result in an empty variable?
With bash >5, I'm trying to assign a different value to variables depending on the architecture specified in a variable. I use a function to do so. This works perfectly:
# arguments:
variable ...
1
vote
1
answer
54
views
correct way of storing external programm and making it executable?
I downloaded the CLI Client habash for the habit/routine gameification project habatica.com.
In the fandom wiki for habash it is written that, I need to set environment variables. Additonally I want ...
1
vote
1
answer
1k
views
Using cURL, jq, and declaration and for loop condition, I tried to download multiple files from a GitLab private repo, but it downloaded only one
I learned from the following sources:
curl -O: Download a file with curl on Linux / Unix command line
jq: How to urlencode data for curl command?
Multiple files and curl -J: download pdf files from ...
5
votes
1
answer
662
views
Declare command and shell expansion
I stumbled by accident on the following bash behaviour, which is for me kind of unexpected.
# The following works
$ declare bar=Hello # Line 1
$ declare -p bar ...
0
votes
1
answer
995
views
Reading variable from a txt file using bash
I'm new to bash.
I'm trying to write a script that will read data from a text find and declare some variables. In the example below we read from a tab delimited file "ab.txt" that looks like this:
...
4
votes
1
answer
1k
views
How to read keyboard input and assign it to a local variable?
I have this very simple script:
#!/bin/bash
read local _test
echo "_test: $_test"
This is the output.
$ ./jltest.sh
sdfsdfs
_test:
I want the variable _test to be local only. Is this possible?
6
votes
2
answers
5k
views
What is a variable attribute?
I aim to understand the general concept of "variable attributes" hoping it will help me understand what is declare in Bash.
What is a variable attribute? Why would someone want to give an attribute ...
9
votes
1
answer
5k
views
Does `declare -a A` create an empty array `A` in Bash?
Does declare -a A create an empty array A in bash, or does it just set an attribute in case A is assigned to later?
Consider this code:
set -u
declare -a A
echo ${#A[*]}
echo ${A[*]}
A=()
echo ${#A[*...
66
votes
5
answers
73k
views
What is "declare" in Bash?
After reading ilkkachu's answer to this question I learned on the existence of the declare (with argument -n) shell built in.
help declare brings:
Set variable values and attributes.
Declare ...