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 :: how to reinstall alsa 
Shell :: install wmctrl 
Shell :: how to use ssh to connect to a remote server in linux 
Shell :: windows terminal 
Shell :: git push existing git repository 
Shell :: sudo pkg instatll lando-stable.deb 
Shell :: Linux get bluetooth mac address 
Shell :: tailwindcss 
Shell :: how to silence operation not permitted 
Shell :: you are running create-react-app 
Shell :: task manager ubuntu 
Shell :: convert dos to unix with tr 
Shell :: gitignore a folder recursively 
Shell :: install docker compose ubuntu 20.04 
Shell :: default .gitignore file 
Shell :: gradle proxy build 
Shell :: git ls-files --others -i --exclude-standard 
Shell :: while loops in bash 
Shell :: How do i search for available packages from the command-line 
Shell :: linux user all permissions 
Shell :: how to pull from specific branch 
Shell :: install wp cli wp org 
Shell :: how to install imsomnia on manjaro linux 
Shell :: command to uninstall windows store 
Shell :: mate on ubuntu 20.04 
Shell :: pg_dump export single table 
Shell :: .bat script on computer startup 
Shell :: git make directory 
Shell :: what is bin/bash 
Shell :: update node with nvm 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =