How to extract the first word from a string in Bash

2 Answers

0 votes
S="bash python java c c++ c#"

first_word=$(echo $S | awk '{print $1}')
echo $first_word



    
    
# run:
#
# bash
#

 



answered May 27, 2021 by avibootz
0 votes
S="bash python java c c++ c#"

echo $S | cut -d " " -f 1



    
    
# run:
#
# bash
#

 



answered May 27, 2021 by avibootz

Related questions

2 answers 491 views
1 answer 332 views
1 answer 383 views
1 answer 360 views
1 answer 358 views
358 views asked May 28, 2021 by avibootz
1 answer 349 views
2 answers 453 views
...