The UNIX and Linux Forums  

Go Back   В UNIX и Linux Форумы > Топ форумы > Shell программирование и сценарии
.
Google unix.com



Shell программирование и сценарии Почтовые вопросы о KSH, CSH, SH, BASH, Perl, PHP, SED, AWK и скрипты оболочки и оболочки скриптовых языков здесь.

Подробнее UNIX и Linux Темы форума можно найти полезные
Нить Резьба для начинающих Форум Ответы Последнее сообщение
getopts с не-вариант аргументов? kdelok Shell программирование и сценарии 2 07-26-2008 11:44 PM
вариант следуют: принимая следующий вариант, если аргумент отсутствует с getopts gurukottur Shell программирование и сценарии 2 03-17-2008 12:46 PM
Помощь в getopts chella Shell программирование и сценарии 4 11-02-2007 01:09 AM
Помощь в getopts проблемы Shell программирование и сценарии 1 05-05-2006 12:07 AM
getopts yerra Shell программирование и сценарии 5 03-26-2005 10:43 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered By Powered by Google
 
LinkBack Резьба Инструменты Искать в этом Thread Оценить Thread Режимы дисплея
Old 08-19-2008
JoeJoseph JoeJoseph is offline
Зарегистрированный пользователь
  
 

Регистрация: август 2008
Сообщений: 1
getopts: плохой вариант (ы)

Привет,

У меня есть сценарий, который выполняется на отлично Solaris 5,8
Однако после обновления Solaris 5.10 началось отсутствии.
Я ссылаться на скрипт как ниже:
./TestScript3.ksh - Реж APP_DATA_IN_OLD $ $ NDM_DATA / $ NEXT_FILE
Когда я исполнить ее, я получаю следующую ошибку "getopts: реж плохой вариант (ы)".
Пожалуйста, дайте мне знать, что изменилось между Solaris 5,8 Solaris 5.10 И причиной этому И каким образом она может быть исправлена. Я новичок в скрипты.
Тело TestScript3.ksh приведена ниже:


Код:
#!/bin/ksh

USAGE="
Usage:  TestScript2 ( --about | --help | --usage | --version )
        TestScript2 [ --bzip ] [ -b|--bzip2] [ -c|--cycle cycles ] [ -d|--date ]
                   [ --dir dir ] [ -f|--force ] [ -g|--gzip ] [ -p|--pack ]
                   [ -s|--silent ] [ -t|--touch ] [ -z|--compress ]
                   file [file ...]
"
HELP="
Options:
        --about         Display information about the program.
        --help          Displays this message.
        --usage         Displays the program's usage.
        --version       Displays the program's version.
        --bzip
                Compress the cycled files with bzip.
        -b, --bzip2
                Compress the cycled files with bzip2.
        -c, --cycle cycles
                Keep 'cycles' number of cycled files. (Default is 3).
        -d, --date
                Append -YYYYMMDDHHMMSS to the cycled files where YYYY is the
                current year; MM is the current month; DD is the current day;
                HH is the current hour; MM is the current minute; and SS is the
                current second.
        --dir dir
                Specify the name of the directory for the cycled files to be
                shifted into.
        -f, --force
                Cycle a file even if it is zero bytes in length.
        -g, --gzip
                Compress the cycled files with gzip.
        -p, --pack
                Compress the cycled files with pack.
        -s, --silent
                Do not display warnings or informational messages.
                Errors will still be displayed.
        -t, --touch
                Create an empty file to replace the cycled file.
        -z, --compress
                Compress the cycled files with compress.
        file
                This is the name of the file to cycle.
"
# Define a restrictive PATH.
#
 export PATH=/usr/xpg4/bin:/usr/bin:/usr/ucb:/usr/local/bin
#export PATH=/bin
# Function to display information about this program.
#
about()
{
        echo
        echo "Copyright (c) 1998 Jim Barber. All rights reserved."
        [[ $change_id != $(eval echo "@(#) \\\$Id\: %\M%,v %\I% %\E% %\U% \\\$" | sed 's/\\//g') ]] && echo "$change_id"
        echo "$ABOUT"
        exit 2
}
# Function to display some help about the program.
#
help()
{
        echo "$USAGE$HELP"
        exit 2
}
# Function to display the usage of this program.
#
usage()
{
        exec >&2
        echo "$USAGE"
        exit 2
}
# Function to display the version of the program.
#
version()
{
        echo
        if [[ $change_id = $(eval echo "@(#) \\\$Id\: %\M%,v %\I% %\E% %\U% \\\$" | sed 's/\\//g') ]]
        then
                echo "cycle_file version 1.1"
        else
                echo $change_id | awk '{printf("cycle_file version %s\n", $4)}'
        fi
        echo
        exit 2
}
# Function to get the argument passed to a long option.
#
# This can't be used if it is valid for the parameter to the long option to
# have a leading '-' (except negative numbers, which are handled correctly).
#
# Example of usage:
#
#       VAR=$(get_long_optarg $OPTARG $OPTIND "$@") || exit ; shift
#
get_long_optarg()
{
        OPTARG=$1
        OPTIND=$2
        shift 2
        if [[ $(eval echo \$$OPTIND) = @(-*) && $(eval echo \$$OPTIND) != @(-)+([0-9])?(.)*([0-9]) || -z $(eval echo \$$OPTIND) ]]
        then
                echo "@basename@: --$OPTARG argument expected" >&2
                usage
        fi
        eval echo \$$OPTIND
}
# Function to convert Access Control Lists to a value suitable for passing to
# the chmod command.
#
acl_to_chmod()
{
        U=$(expr "$1" : '.\(...\)......')
        G=$(expr "$1" : '....\(...\)...')
        O=$(expr "$1" : '.......\(...\)')
        echo "u=$U,g=$G,o=$O" | sed 's/-//g; s/s/sx/g; s/S/s/g; s/t/tx/g; s/T/t/g'
}
# Initialise some parameters.
#
unset COMPRESS DATE DIR FORCE SILENT TOUCH
CYCLES=3
# Parse the command line parameters.
#
OPTIND=1
while getopts 'bc:dfgpstz-:' PARAMS
do
        case "$PARAMS" in
                b) COMPRESS='bzip2 -9' ;;
                c) CYCLES=$OPTARG ;;
                d) DATE=$(date "+%Y%m%d%H%M%S") ;;
                f) FORCE=true ;;
                g) COMPRESS='gzip -9' ;;
                p) COMPRESS=pack ;;
                s) SILENT=true ;;
                t) TOUCH=true ;;
                z) COMPRESS=compress ;;
                -)
                case "$OPTARG" in
                        about)          about ;;
                        help)           help ;;
                        usage)          usage ;;
                        version)        version ;;
                        bzip)           COMPRESS=bzip ;;
                        bzip2)          COMPRESS='bzip2 -9' ;;
                        compress)       COMPRESS=compress ;;
                        cycle)          CYCLES=$(get_long_optarg $OPTARG $OPTIND "$@") || exit ; shift ;;
                        date)           DATE=$(date "+%Y%m%d%H%M%S") ;;
                        dir)            DIR=$(get_long_optarg $OPTARG $OPTIND "$@") || exit ; shift ;;
                        force)          FORCE=true ;;
                        gzip)           COMPRESS='gzip -9' ;;
                        pack)           COMPRESS=pack ;;
                        silent)         SILENT=true ;;
                        touch)          TOUCH=true ;;
                        *)
                        echo "Illegal option --$OPTARG" >&2
                        usage ;;
                esac ;;
                \?)     usage ;;
        esac
done
shift $((OPTIND - 1))
echo $DIR
# Make sure that at least one file name was passed.
#
(( $# < 1 )) && usage
# Make sure that the directory for the log files to to be cycled to exists.
#
if [[ -n $DIR && ! -d $DIR ]]
then
        echo "Error: '$DIR' is not a valid directory."
        exit 1
fi
echo $@
for REAL_FILE in "$@"
do
        # Only do the cycle if the file exists.
        #
        if [[ ! -f $REAL_FILE ]]
        then
                [[ -z $SILENT ]] && echo "File '$REAL_FILE' does not exist. Skipping..." >&2
                RET_CODE=1
                continue
        else
        echo "File exists"
        fi
done
# Set a return code for the program.
#
RET_CODE=0
exit $RET_CODE

 

Закладки

Резьба Инструменты Искать в этом Thread
Искать в этом Thread:

Расширенный поиск
Режимы дисплея Оценить эту ветку
Оценить эту ветку:

Отправка Правила
Вы не может Начать новую нитей
Вы не может Почтовые ответы
Вы не может Почтовые вложения
Вы не может Редактировать Ваши сообщения

BB код быть На
Смайлики являемся На
[IMG] код На
HTML-код Вне
Trackbacks являемся На
Pingbacks являемся На
Refbacks являемся На




Часовой пояс GMT -4. Текущее время 02:08 AM.


Powered By: Справка, Copyright © 2000 - 2006, Jelsoft Enterprises Limited. Язык Переводы на питание от .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
В UNIX и Linux форумы Содержание Copyright © 1993-2009. Все права Reserved.Ad управления по RedTyger

Содержание соответствующие URL-адреса в vBSEO 3.2.0