How to assign to a bash variable the first result of locate? -
i can allocate path variable bash:
var1=/home/alvas/something
i can find automatically:
$ cd $ locate -b "something" . /home/alvas/something /home/alvas/someotherpath/something
but how assign first result locate variable's value?
i tried following doesn't work:
alvas@ubi:~$ locate -b 'mosesdecoder' . | var1= alvas@ubi:~$ var1 var1: command not found
you need assign output of locate
command variable:
var1=$(locate -b 'mosesdecoder' . | head -n 1)
(use head
top n
lines).
the construct $(...)
called command substitution , can read in command substitution section of bash reference manual or of posix shell specification.
Comments
Post a Comment