![이 bash 변수에 내가 뭘 잘못하고 있는 걸까요? [폐쇄]](https://linux55.com/image/61479/%EC%9D%B4%20bash%20%EB%B3%80%EC%88%98%EC%97%90%20%EB%82%B4%EA%B0%80%20%EB%AD%98%20%EC%9E%98%EB%AA%BB%ED%95%98%EA%B3%A0%20%EC%9E%88%EB%8A%94%20%EA%B1%B8%EA%B9%8C%EC%9A%94%3F%20%5B%ED%8F%90%EC%87%84%5D.png)
명령에 변수를 어떻게 삽입할 수 있나요? 아래의 경우 명령을 변수 파일 이름과 연결해야 합니다.
#!/bin/bash
# Define a timestamp function
timestamp() {
date +"%D-%T" | tr :/ -
}
# Define the file name
value=$(timestamp)
filename= "/home/pi/media/$value.h264"
#Recording
raspivid -w 800 -h 600 -t 15000 -o $filename -n -rot 270
#Terminate the script
exit
답변1
뒤에 공백을 추가할 수 없으며 filename=
공백만 제거하면 됩니다.
답변2
처음에 왜 할당 timestamp
합니까 value
? 다음을 수행할 수 있습니다.
filename="/home/pi/media/"$(timestamp)".h264"
그리고 녹음 명령에서 파일 이름을 인용해야 합니다(경로 등에 공백이 있는 경우).
#Recording
raspivid -w 800 -h 600 -t 15000 -o "$filename" -n -rot 270