Skip to main content

All Questions

1 vote
1 answer
5k views

Putting string with newline separated words into array

I currently have a a bash variable that holds a string similar to this one, where each different phrase is separated by a newline: var="1st word 2nd word 4th word" Note there is an empty ...
lilek3's user avatar
  • 77
0 votes
1 answer
814 views

More efficient zsh string parsing / array handling

Is there any more efficient way to do the following in zsh? I imagine that there might be ways to get rid of the intermediate array parameters a and/or b. The script gets some output from a command. ...
XDR's user avatar
  • 451
2 votes
4 answers
970 views

String Manipulation Shell Script [duplicate]

I am working on a UPS Monitoring project using NUT Server. My objective is to make a shell script which sends one command and in response receives the status and other parameters from the UPS. for ...
Kunal Sonone's user avatar
18 votes
3 answers
22k views

Go from a String to an Array of "words" in Bash

I need to go from a string to an array where each entry is each word on that string. For example, starting with: VotePedro="Vote for Pedro" I need the array: Vote For Pedro Which I should then be ...
farid99's user avatar
  • 573
15 votes
4 answers
18k views

How can I prepend and append to each member of an array?

I have an array: CATEGORIES=(one two three four) I can prepend to each array member using parameter expansion: echo ${CATEGORIES[@]/#/foo } I can append to each array member the same way: echo ${...
Big McLargeHuge's user avatar
7 votes
2 answers
8k views

Splitting the working directory in a bash script

If I do: IFS="/" read -ra PARTS And type in a path manually, it creates the array "PARTS" as hoped, however: IFS="/" read -ra PARTS <<< $(pwd) creates an array with a single element, with ...
Brent's user avatar
  • 234
5 votes
4 answers
10k views

Bash : Native way to get rid of quotation around each array member

I read an array from another script. This array needs to put " " around all array members since some members are empty. in_file=./data vector=($(./readdata.sh 0 $in_file)) for index in ${!vector[@]} ...
ar2015's user avatar
  • 212
1 vote
2 answers
3k views

Read file remove spaces and store in array

I have a file with the following content: list: blue,none red,none orange,plot baseball , none university,none school,none desk,plot monitor,none earphone,none I need to read this file, ...
ar2015's user avatar
  • 212
2 votes
1 answer
1k views

Generate array of strings combined with number

I would like to generate a local array in a shell/bash script that consists of the following elements: JF-1998, JF-1999, JF-2000,... , JF-2011. That is, a string JF- combined with the years from 1998 ...
MERose's user avatar
  • 537
1 vote
1 answer
1k views

Zsh script how to concatanate array elements with string

I have written a zsh script to automize an analysis in high energy physics and now I would like to use an element of the one of the defined array some string and another element of some another array ...
Vesnog's user avatar
  • 689