
쉘 스크립트의 다음 부분이 있습니다.
#!/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|합계' ./copyFilesFromS13.sh: 54행: aws s3 ls --사람이 읽을 수 있음 --summarize s3://ssyssplunk/ --recursive: 해당 파일 또는 디렉터리가 없습니다. 전체 크기:
내가 도대체 뭘 잘못하고있는 겁니까 ?
답변1
IFS를 개행 문자와 백스페이스로만 설정했습니다. 따라서 확장 및 단어 분할 후에는 단일 단어로 간주 $s3ls
됩니다 . Bash는 여러 인수를 사용하여 aws s3 ls --human-readable --summarize s3://ssyssplunk/ --recursive
실행하는 대신 이 단일 단어를 명령으로 실행하려고 합니다 .aws
실제로 명령을 변수에 저장하면 안 됩니다.대신 배열을 사용하세요:
s3ls=(aws s3 ls --human-readable --summarize 's3://ssyssplunk/' --recursive)
#...
totalSize=$("${s3ls[@]}" | ...)