【发布时间】:2022-01-22 05:55:07
【问题描述】:
这是代码,我想运行这个命令
获取 test.log 输入,然后将其转换为 text 类型,然后将其存储在output.txt 文件
./small.sh test.log -t text -o output.txt
#!/usr/bin/env bash
usage() { echo "$0 usage:" && grep " .)\ #" $0; exit 0; }
[ $# -eq 0 ] && usage
parse()
{
local file=$1
local type=$2
local output=$3
echo "file: ${file}, type: ${type}, output: ${output}"
}
while getopts ":ht:o:" arg; do
case $arg in
t) # specify type.
type=${OPTARG} ;;
o) # specify directory.
output=${OPTARG} ;;
h | *) # Display help.
usage
exit 0
;;
esac
done
shift $(( OPTIND - 1))
parse "${file}" "${type}" "${output}"
使用此代码,我只能在像这样将其按未排序顺序放置文件名时获取文件名
./small.sh -t text -o output.txt test.log
【问题讨论】:
-
常规顺序为
./small.sh -t text -o output.txt test.log