Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash assigning to new array

ss="abcdefghi"
my_array=( `echo $ss | grep -o . ` )

### without for loops ###########
declare -a NewArray=("${my_array[@]}")
echo ${NewArray[@]}

########### using a for loop #################
for i in "${my_array[@]}"
do
     new_array+=($i)
done

for i in "${new_array[@]}"
do
	echo $i
done

Comment

bash assign array to variable

#create array:  or for int..  myArray=(1 2 3 4 5)
declare -a myArray=("cat" "dog" "mouse" "frog")
#to copy array instead of referencing aka array.slice(0)
declare -a myNewArray=("${myArray[@]}")
#slice array: returns ("cat" "dog")
declare -a myFirstHalf=( "${array[@]:0:2}" )
Comment

PREVIOUS NEXT
Code Example
Shell :: E: Unable to locate package libclang-cpp-dev 
Shell :: how to make a file executable in linux 
Shell :: check scheduler on localhost laravel 
Shell :: fstab sshfs 
Shell :: how to open files using terminal in ubuntu 
Shell :: wget debian 
Shell :: install solidity compiler command with version 
Shell :: add colab to github 
Shell :: git flow feature 
Shell :: skip ci gitlab 
Shell :: add project to github 
Shell :: creating new repository 
Shell :: ansible playbook omit tag 
Shell :: linux calculator 
Shell :: rickroll ssh 
Shell :: zsh print each line of script 
Shell :: c# check if word is installed 
Shell :: deno bundler 
Shell :: zsh get first line 
Shell :: sqliteman linux 
Shell :: list relative path windows 
Shell :: ng table angular 9 install 
Shell :: gradle init scala 
Shell :: view nohup output 
Shell :: bash variable substitution 
Shell :: run katalon docker image 
Shell :: sudo: gitlab-runner: command not found 
Shell :: use localhost for self signed cert 
Shell :: copiar arichvos linux ssh 
Shell :: bash script perform root access check 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =