![명령 매개변수가 작동하지 않는 Bash 스크립트](https://linux55.com/image/148230/%EB%AA%85%EB%A0%B9%20%EB%A7%A4%EA%B0%9C%EB%B3%80%EC%88%98%EA%B0%80%20%EC%9E%91%EB%8F%99%ED%95%98%EC%A7%80%20%EC%95%8A%EB%8A%94%20Bash%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8.png)
bash 스크립트를 사용하십시오 ./find_dates
. 코드는 다음과 같습니다.find_dates
grep '^2019/02/01' /pi/home/data/*|sort -t: -k2 > /pi/home/files/data.txt;
데이터를 가져오는 중이에요data.txt
그러나 내가 달릴 때 ./find_dates2 2019/02/01
. 코드는 다음 위치에 있습니다 find_dates2
.
grep '^$1' /pi/home/data/*|sort -t: -k2 > /pi/home/files/data.txt;
비 었다 data.txt
.
답변1
단순 오타 - 작은따옴표 대신 큰따옴표를 사용하십시오. 그렇지 않으면 변수가 확장되지 않습니다.
grep "^$1" /pi/home/data/*|sort -t: -k2 > /pi/home/files/data.txt;