unix - read a value from list and writing it in command line in shell script -
this question has answer here:
- list files , show them in menu bash 2 answers
need in reading value list , writing input next command.
i need write shell script needs have
git tag -l
--- list out tags or version numbers like:v1.0 v2.0 v3.0 v4.0
i need read 1 of value list output say, v3.0 , pass next command
read v3.0
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
Post a Comment