Questions tagged [declare]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
1answer
56 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
1answer
275 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
1answer
119 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: ...
1
vote
1answer
93 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?
1
vote
2answers
719 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 ...
7
votes
1answer
1k 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[*...
13
votes
4answers
4k 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 ...
3
votes
3answers
2k views

Function to conditionally set a variable read-only

If I had a script which sets variables read-only to some odd values, and sets errexit because of other unsafe operations: #!/bin/bash set -e declare -r NOTIFY=$(case "$OS" in (macosx) echo ...
0
votes
2answers
26 views

Parse 3rd entry in declare result

I have this: cd 31 /Users/alexamil/WebstormProjects/oresoftware/botch/botch-shell-overrides.sh the above style output, is given by this command: declare -F my_bash_func How can I grab just the ...