Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash count elements in string

# Basic syntax:
YOUR_VAR=( $YOUR_VAR ) # convert the string to an array
echo ${#YOUR_VAR[*]} # use the standard bash syntax to get the length of arrays

# Example usage:
YOUR_VAR='some string with words'
YOUR_VAR=( $YOUR_VAR )
echo ${#YOUR_VAR[*]}
--> 4

# Note, to convert the array back to a string, use:
YOUR_VAR="${YOUR_VAR[*]}"
Comment

PREVIOUS NEXT
Code Example
Shell :: linux while true 
Shell :: Could not resolve HEAD to a revision 
Shell :: kafka confluent download 
Shell :: npm install capacitor to existing angular project 
Shell :: conda create tensorflow-gpu environment 
Shell :: redis remove key 
Shell :: get all pods in a node kubectl 
Shell :: set terminator as default 
Shell :: convert ppk to pem 
Shell :: how to set global github username and password in git 
Shell :: how to install moment in vuejs 
Shell :: Reading state information... Done E: Unable to locate package docker-ce 
Shell :: docker up frce recreate 
Shell :: get public key pem from cert 
Shell :: linux x11 dev 
Shell :: github restore previous commit 
Shell :: install.packages( tidyverse ) not working 
Shell :: linux shell arguments 
Shell :: see output of a running processes linux 
Shell :: wsl2 settings 
Shell :: uninstall ros2 foxy 
Shell :: git change file case windows 
Shell :: how to see hidden files in terminal mac 
Shell :: log cpu usage on linux 
Shell :: printf @ bash 
Shell :: openssl serial number 
Shell :: git revert all commits to pervious commit 
Shell :: setup redis ubuntu 
Shell :: copy from server to local scp 
Shell :: install sketch for ubuntu 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =