LINUX.ORG.RU

Double dash при передаче параметров из одного скрипта в другой

 


0

1

Добрый день.

Столкнулся с такой передачей из скрипта в скрипт и не могу понять, что передается.

скрипт 1.

local/data_split.sh --every_n $EVERY_N $DATA_ROOT $WORK/local «$LMs» «$TEST_SETS» || exit 1

скрипт 2 (data_split.sh).

Первая же строка every_n=1

Что обозначает --?

Заранее спасибо.


Второй скрипт дальше первой строки прочитай

Black_Shadow ★★★★★
()

всего навсего соглашение «длинное имя опции». короткие опции можно передавать группой, предваряя группу одном знаком минус,
rm -rf или rm -fr
или отдельно rm -r -f
а длинные
rm --recursive --force

http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html
GNU adds long options to these conventions. Long options consist of ‘--’ followed by a name made of alphanumeric characters and dashes. Option names are typically one to three words long, with hyphens to separate words. Users can abbreviate the option names as long as the abbreviations are unique.

To specify an argument for a long option, write ‘--name=value’. This syntax enables a long option to accept an argument that is itself optional.

bl ★★★
()
Ответ на: комментарий от GH12

"--" - это просто соглашение об именовании опций. Само по себе оно не работает. В Вашем случае «London» доступна как «$2» или при помощи GNU getopt (см. man getopt).

Можно также парсить опции вручную или при помощи встроенной в bash команды getopts. См. http://www.tldp.org/LDP/abs/html/extmisc.html#GETOPTY http://www.tldp.org/LDP/abs/html/internal.html#GETOPTSX

AITap ★★★★★
()
Последнее исправление: AITap (всего исправлений: 2)
Ответ на: комментарий от AITap

every_n=1

[ -f path.sh ] && . ./path.sh # source the path. . utils/parse_options.sh || exit 1;

if [ $# -ne 4 ] ; then echo «Usage: local/data_split.sh [--every-n 30] <data-directory> <local-directory> <LMs> <Test-Sets> <tgt-dir>»; exit 1; fi

DATA=$1; shift locdata=$1; shift LMs=$1; shift test_sets=$1; shift tgt_dir=$1; shift

echo «LMs $LMs test_sets $test_sets»

echo «=== Starting initial Vystadial data preparation ...» echo "--- Making test/train data split from $DATA taking every $every_n recording..."

mkdir -p $locdata

i=0 for s in $test_sets train ; do mkdir -p $locdata/$s ls $DATA/$s/ | sed -n /.*wav$/p |\ while read wav ; do ((i++)) # bash specific if [[ $i -ge $every_n ]] ; then i=0 pwav=$DATA/$s/$wav echo «$wav $pwav» >> $locdata/$s/wav.scp fi done # while read wav

for f in wav.scp utt2spk spk2utt trans.txt ; do sort «$locdata/$s/$f» -k1 -u -o «$locdata/$s/$f» # sort in place done # for f

done # for in $test_sets train

Вот второй скрипт. Зачем нужно --, вместо простой передачи числа, не понятно.

GH12
() автор топика
Ответ на: комментарий от GH12

Зачем нужно --, вместо простой передачи числа, не понятно.

Автор скрипта счёл нужным обозначить опциональный параметр отдельно от обязательных? Альтернативой было бы сделать его шестым параметром.

. utils/parse_options.sh

Если интересно, внутри этого файла должна быть реализация работы с --параметрами.

AITap ★★★★★
()
Ответ на: комментарий от AITap

Да, внутри utils/parse_options.sh

# Parse command-line options. # To be sourced by another script (as in ". parse_options.sh"). # Option format is: --option-name arg # and shell variable «option_name» gets set to value «arg.»

Теперь стало проясняться. Спасибо.

GH12
() автор топика
Ответ на: комментарий от GH12

велосипеды не нужны

DESCRIPTION getopt is used to break up (parse) options in command lines for easy parsing by shell procedures, and to check for legal options. It uses the GNU getopt(3) routines to do this.

The parameters getopt is called with can be divided into two parts: options which modify the way getopt will parse (options and -o|--options optstring in the SYNOPSIS), and the parameters which are to be parsed (parameters in the SYN‐ OPSIS). The second part will start at the first non-option parameter that is not an option argument, or after the first occurrence of `--'. If no `-o' or `--options' option is found in the first part, the first parameter of the second part is used as the short options string.

If the environment variable GETOPT_COMPATIBLE is set, or if its first parameter is not an option (does not start with a `-', this is the first format in the SYNOPSIS), getopt will generate output that is compatible with that of other ver‐ sions of getopt(1). It will still do parameter shuffling and recognize optional arguments (see section COMPATIBILITY for more information).

Traditional implementations of getopt(1) are unable to cope with whitespace and other (shell-specific) special charac‐ ters in arguments and non-option parameters. To solve this problem, this implementation can generate quoted output which must once again be interpreted by the shell (usually by using the eval command). This has the effect of preserving those characters, but you must call getopt in a way that is no longer compatible with other versions (the second or third for‐ mat in the SYNOPSIS). To determine whether this enhanced version of getopt(1) is installed, a special test option (-T) can be used.

emulek
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.