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 :: change default location screen mac 
Shell :: how to delete an issue on github 
Shell :: how to add ssh key to github 
Shell :: print first word of each line by grep 
Shell :: open a file in linux 
Shell :: wget debian to Downloads 
Shell :: create a new branch based on another branch 
Shell :: launch sublime from terminal 
Shell :: should you use docker on linux 
Shell :: pdf file 30mb 
Shell :: get logs from application isntaller 
Shell :: git get latest log output to file 
Shell :: docker cmd multiple commands 
Shell :: linux vi 
Shell :: check for installed chaincode 
Shell :: A server is already running. Check /home/mahi/Desktop/PharmaPlace/tmp/pids/server.pid. Exiting 
Shell :: rsync full disk backup 
Shell :: uninstall en_web_core md 
Shell :: start-process argumentlist with spaces powershell 
Shell :: how to troll someone 
Shell :: bash read full file 
Shell :: jq for xml 
Shell :: very strong ssh encryption key 
Shell :: aws cli start crawler 
Shell :: bash variable in string 
Shell :: get rasbien version 
Shell :: bind folder linux 
Shell :: fork() system call in linux 
Shell :: find and move bash 
Shell :: nextcloud config.php location docker 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =