unix - read a value from list and writing it in command line in shell script -


this question has answer here:

need in reading value list , writing input next command.

i need write shell script needs have

  1. git tag -l --- list out tags or version numbers like:

    v1.0 v2.0 v3.0 v4.0 
  2. i need read 1 of value list output say, v3.0 , pass next command

  3. read v3.0

  4. git checkout <version number> example: git checkout v3.0

how achieve in shell scripting? pls help

reading last comment, think @fedorqui right. question duplicate: build menu , prompt user. in situation should use options=( $(git tag -l) ).

the script @ list options in menu in bash becomes:

#!/bin/bash  prompt="please select file:" options=( $(git tag -l) )  ps3="$prompt " select opt in "${options[@]}" "quit" ;      if (( reply == 1 + ${#options[@]} )) ;         exit      elif (( reply > 0 && reply <= ${#options[@]} )) ;         echo  "you picked $opt file $reply"         break      else         echo "invalid option. try one."     fi done      git checkout $opt 

----

first answer history.

the command looking xargs:

git tag -l | fgrep v3.0 | xargs -i xxx git checkout xxx 

i have warn you, if more 1 tag contain v3.0 git checkout executed more once.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -