grepコマンドを使用したbashスクリプトは[重複]ではありません

grepコマンドを使用したbashスクリプトは[重複]ではありません

シェル スクリプトの次の部分があります:

#!/bin/bash
shopt -s extglob
currentDate=$(date +%F)

echo $currentDate
command="grep $currentDate"
gcs3='s3://gc-reporting-pud-production/splunk_printer_log_files'
gcs3ls='aws s3 ls 's3://gc-reporting-pud-production/splunk_printer_log_files/SOUTH_ASIA/' --recursive '
ssyss3=s3://ssyssplunk

gcs3Current=$($gcs3ls|$command|sed 's/^.*\(splunk_printer.*\)/\1/g')

SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
s3ls='aws s3 ls --human-readable --summarize 's3://ssyssplunk/' --recursive'
echo "ls: " $s3ls
egrepCommand="'$currentDate|Total'"
echo "grep: " $egrepCommand
totalSize=$($s3ls|egrep $currentDate\|Total|awk -F 'Total Size:' '{print $2}'|sed '/^$/d')
echo "total size: "  $totalSize
IFS=$SAVEIFS

そしてこのエラーが発生します:

2019-05-27 ls: aws s3 ls --human-readable --summarize s3://ssyssplunk/ --recursive grep: '2019-05-27|Total' ./copyFilesFromS13.sh: 行 54: aws s3 ls --human-readable --summarize s3://ssyssplunk/ --recursive: そのようなファイルまたはディレクトリはありません 合計サイズ:

何が間違っているのでしょうか?

答え1

IFS を改行とバックスペースのみに設定しました。したがって、$s3ls展開と単語分割の後、 は 1 つの単語として扱われます。Bash は、一連の引数でaws s3 ls --human-readable --summarize s3://ssyssplunk/ --recursive実行するのではなく、この 1 つの単語をコマンドとして実行しようとします。aws

実際には、コマンドを変数に保存するべきではありません。代わりに配列を使用する:

s3ls=(aws s3 ls --human-readable --summarize 's3://ssyssplunk/' --recursive)
#...
totalSize=$("${s3ls[@]}" | ...)

関連情報