Linked Questions

2 votes
3 answers
1k views

I'm trying to make a menu function, and have the following script segment, which is meant to split a comma separated list of values into an array: IFS=, read -r -a optionList <<< $3 However, ...
BryKKan's user avatar
  • 478
2 votes
1 answer
5k views

I have the following line filename:231:blahblah that I want to split into an array using : as the delimiter The is the code that I have echo "Text read from file: $line" IFS=':' read -a FILENAME <...
Sahar Rabinoviz's user avatar
1 vote
1 answer
2k views

I'm new shell scripting and have a quick question about my code. This works: x=2 y=4 z=6 x=$(( $x-1 )) y=$(( $y-2 )) z=$(( $z-3 )) echo $x $y $z $ script.sh 1 2 3 And this works: n=2,4,6 IFS=$',' ...
bggarchow's user avatar
4 votes
2 answers
123 views

I am running Bash version 4.2.25. Here is my code: #!/usr/bin/env bash string="one:two:three:four" # without quotes IFS=: read -ra array_1 <<< $string for i in "${array_1[@]}"; do printf "...
codeforester's user avatar
  • 43.8k
1 vote
1 answer
84 views

I have encountered a strange behavior when using the read command and unquoted here-string when they still used to be subject to word-splitting (in older versions of bash). Please take a look at the ...
mickp's user avatar
  • 1,852
3030 votes
40 answers
3.9m views

I have this string stored in a variable: IN="[email protected];[email protected]" Now I would like to split the strings by ; delimiter so that I have: ADDR1="[email protected]" ADDR2="[email protected]" I don't ...
stefanB's user avatar
  • 80.4k
7 votes
3 answers
10k views

I have to split a URL string and assign variables to few of the splits. Here is the string http://web.com/sub1/sub2/sub3/sub4/sub5/sub6 I want to assign variables like below from bash var1=sub2 var2=...
kuruvi's user avatar
  • 663
1 vote
2 answers
1k views

I am trying to initialize read an array by splitting a variable. x=abc:def:gh declare -a xa # I want xa[0] = abc, xa[1] = def, and so on IFS=: read -a xa <<< $x echo ${#xa[@]} $xa ######### ...
Dinesh's user avatar
  • 4,569
1 vote
2 answers
4k views

I am trying to make a script to get ip list from file and show it on screen with select option, and make ssh to that IP just by selecting. File is like below; name1 1.1.1.1 name2 2.2.2.2 name3 3.3.3....
thanksforanswer's user avatar
0 votes
1 answer
556 views

Running these commands gives expected results $ bash --version GNU bash, version 4.1.11(2)-release $ foo=(111 222 333) $ IFS=, cat <<< "${foo[*]}" 111,222,333 However it appears with Bash ...
Zombo's user avatar
  • 1
0 votes
2 answers
355 views

Here's a link I referred this but I am not able to understand, how I can split: Testing123 into Testing and 123 temp=${str%%:*} #only if there was colon in between but in my case there isn't. If ...
kyle's user avatar
  • 113
3 votes
1 answer
157 views

Platform CentOS Linux release 7.6.1810, working in bash. GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu) This is an idiom I've seen recommended for parsing text in bash in general and ...
djna's user avatar
  • 56.2k
0 votes
1 answer
94 views

I have the following arrays defined in a bash script IFS=, read -r -a start_files <<< $(head -n 1 file.txt) IFS=, read -r -a end_files <<< $(tail -n 1 file.txt) I read also two ...
user avatar
0 votes
1 answer
101 views

I want to read result of ps command and the proc number into two variables, but all the output assigned to the first variable. my shell followed like this #!/bin/bash function status() { proc_num=...
Cans404's user avatar
  • 13
1 vote
1 answer
79 views

I have a function that returns several string separated by "|" and i am using read to parse them in tokens. Some of the strings might contain newlines (i.e. \n) but from my perspective read ...
user23691540's user avatar