Linked Questions

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 ...
pathikrit's user avatar
  • 33.5k
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? ...
Theo's user avatar
  • 1
-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 ...
bigdoyle's user avatar
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[@]} ...
thoni56's user avatar
  • 3,305
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?
Paolo Tedesco's user avatar
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" ...
whateverrest's user avatar
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 $...
dandu's user avatar
  • 800
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 ...
NPS's user avatar
  • 6,213
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 ...
Sun Bear's user avatar
  • 8,112
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: ...
Indigo Psy's user avatar
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" ...
TonyL2ca's user avatar
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 ...
Frank Bergemann's user avatar
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 \*....
fbicknel's user avatar
  • 1,303
-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 ...
kmt's user avatar
  • 45
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 ...
rollingovermycode's user avatar

15 30 50 per page