Linked Questions
16 questions linked to/from Bash array with spaces in elements
1
vote
0
answers
492
views
How to pass arrays with spaces as function arguments in Bash [duplicate]
I have the following script:
brews=(
java8
archey
aws-shell
"bash-snippets --without-all-tools --with-weather"
cheat
coreutils
dfc
findutils
"fontconfig --universal"
fpp
fzf
...
0
votes
1
answer
315
views
shell bash array: values with whitespace put it together [duplicate]
I need to add values into an array, but some values are separated with a whitespace.
Then would be so fo example:
"hello world"
myarr[0]: "hello
myarr[1]: world"
How can I put it all together?
...
-1
votes
2
answers
215
views
bash array syntax and loops, please explain [duplicate]
I get confused on array syntax in bash. I typically use quotes to enclose strings to loop through, but tutorials typically use parentheses. For kicks I made 4 simple loops. The first two work as I ...
0
votes
0
answers
38
views
Keep variables including spaces when calling command in bash script [duplicate]
In a script such as this
#! /bin/bash -i
arguments=(arg1 "arg2 has many spaces")
echo arguments count = ${#arguments[@]}
echo arguments = ${arguments[@]}
echo ls ${arguments[@]}
ls ${arguments[@]}
...
808
votes
45
answers
943k
views
Check if a Bash array contains a value
In Bash, what is the simplest way to test if an array contains a certain value?
3
votes
4
answers
6k
views
Cut / echo inside bash [duplicate]
Im confused with how the following cut works in the bash script.
Sample of file.csv:
#10.10.10.10;28;9.10.10.10: up;Something ;More random spaces
My script:
#!/bin/bash
csv_file="file.csv"
...
5
votes
2
answers
2k
views
POSIX SH build loop variable with elements containing spaces
Here's the code I need:
#!/bin/sh
x1="a1 a2"
x2="b1 b2"
list=SOMETHING
for x in "$list"
do
echo $x
done
And the output I want:
a1 a2
b1 b2
The question is: what should SOMETHING be? I want $...
0
votes
2
answers
897
views
Array elements with spaces are arguments to a function
myFunction()
{
> /tmp/file_$1_$2
}
ELEMENTS=("first" "second" "a third" "a fourth")
for elem in "${ELEMENTS[@]}"
do
myFunction "$elem"
done
I've tried the above code and a bunch of other ...
1
vote
4
answers
727
views
How to use bash to touch and ln array elements?
I created the following code:
#!/bin/bash
rdir="~/bin/Test/"
echo $rdir
echo $rdir"folderA"
/bin/mkdir -p $rdir"folderA"
# files is an array. () is used to enclose array elements and
# each ...
0
votes
1
answer
653
views
Bash - Compare User input with array [duplicate]
I want to validate did user input proper device in whiptail dialog or did user input something wrong.
I'm googling this for 2 days and can'f find any similar question/issue.
This is my code:
...
2
votes
4
answers
164
views
find a option in string split by space in bash
I have a string like this, name it Options:
"printer-is-accepting-jobs=true printer-is-shared=false printer-location=Library printer-make-and-model='HP LaserJet 600 M601 M602 M603' printer-state=3"
...
1
vote
3
answers
301
views
bash: filter list of files, that can contain spaces" - associative array required?
I want to create a list of filenames - that might have some filenames with spaces within.
This list shall be filtered in bash (not with 'find' itself - or alike).
The final list has to be processed ...
0
votes
1
answer
214
views
How do you assign lines of output containing spaces to a bash array [duplicate]
I would like to take the output of something that returns lines of elements possibly containing spaces to a bash array, with each line getting its own array element.
So for example:
find . -name \*....
-2
votes
1
answer
81
views
bash grep can return an empty space, how to substitute the empty space for a string?
I am attempting to grep an inbox for survey results, in which the subject will include the answer to the following question:
"The answer to your question is ___"
The answered question will ...
0
votes
1
answer
75
views
Bash - issues with creating arrays from elements containing whitespaces (jq-formatted output as input) [duplicate]
I am working on a bash script which needs to ingest some data from a json (formatted with jq) and do some simple work with it, however in the process of doing so I noticed elements are getting broken ...