How to get first string from a bash list? -


i have bash list (space separated string) , want extract first string it.

example:

 var="aaa bbb ccc" -> need "aaa"  var="xxx" -> need "xxx" 

is there other trick using break ?

try format:

echo "${var%% *}" 

another way is:

read first __ <<< "$var" echo "$first" 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -