2

presto is distributed SQL query engine ,

and when we installed the presto then it should be created the following home folder

/application/DB/presto/presto-server-0.216

so we can say that

in order to capture the home presto we can do ( its part of my bash script )

PRESTO_HOME=` find  /application/DB/presto/ -maxdepth 1 | grep  presto-server `
echo $PRESTO_HOME
/application/DB/presto//presto-server-0.216

BUT ... since some users can rename the folder under /application/DB/presto/ in order to install new version

then under /application/DB/presto , we can get the following folders:

/application/DB/presto/presto-server-HOLD_0.211
/application/DB/presto/_presto-server-0.212
/application/DB/presto/backup_presto-server-0.216.new
/application/DB/presto/presto-server-0.210.old
/application/DB/presto/presto-server-0.212.orig

so regarding that

what is the right syntax in order to find the real path as

/application/DB/presto/presto-server-0.216

notes:

presto folder structure is always with

presto-server-[ any float number or integer number ]

VALID examples:

/application/DB/presto/presto-server-0.736
/application/DB/presto/presto-server-0.936
/application/DB/presto/presto-server-1
/application/DB/presto/presto-server-1.9
/application/DB/presto/presto-server-12

NON VALID examples:

/application/DB/presto/presto-server-0.736-43.previos
/application/DB/presto/presto-server-0.936_old
/application/DB/presto/orig_presto-server-1
/application/DB/presto/presto-server-1.9.bck
/application/DB/presto/presto-server-PREVIOS
/application/DB/presto/presto-server-
/application/DB/presto/presto-server-0.936_old
/application/DB/presto/orig_presto-server-1.other
/application/DB/presto/presto_server-1.9.bck
/application/DB/presto/OLD_presto-server-12-83
3

Depending on which shell you're using, you could do it with globbing.

bash

#! /bin/bash -
shopt -s nullglob extglob
dirs=(/application/DB/presto/presto-server-+([[:digit:]])*(.+([[:digit:]])))

printf '%s\n' "Found ${#dirs[@]} matching directories:" "${dirs[@]}"

zsh

#! /bin/zsh -
set -o extendedglob
dirs=(/application/DB/presto/presto-server-<->(.<->)#(N))

printf '%s\n' "Found $#dirs matching directories:" $dirs

ksh93

#! /bin/ksh93
dirs=(~(N)/application/DB/presto/presto-server-+([[:digit:]])*(.+([[:digit:]])))

printf '%s\n' "Found ${#dirs[@]} matching directories:" "${dirs[@]}"

For all, that's presto-server- followed by a sequence of 1 or more digits followed by 0 or more sequences of .<digits>.

  • clever with the printf '%s\n' ...! – Jeff Schaller Feb 27 at 20:12
  • what is the meaning of - shopt -s nullglob extglob – yael Mar 4 at 11:35
1

With GNU find's -regex test, you could use:

find /application/DB/presto/ -regex '/application/DB/presto/presto-server-\([0-9]*\.\)?[0-9]+'

... which requires the leading path, and then the numeric part:

  • optionally: leading digits and a period
  • one or more digits

That matches all and only your "valid" examples, and none of your "invalid" examples.

Change the [0-9]* to [0-9]+ if you want to require a digit before any leading period; the difference between:

/application/DB/presto/presto-server-0.936

and

/application/DB/presto/presto-server-.936

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.